1

当以编程方式调用wireMockServer.stop() 时,测试卡在这个无限关闭循环中。作为一种解决方法,我将其设为静态,但我想为每次测试重新启动服务器。关于如何使这项工作的任何想法?下面是测试代码以及​​我在调用wireMockServer.stop() 后看到的日志,并且测试卡在这个无限循环中。

public class StackOverflowApplicationTest extends ApplicationTestCase<MyApplication> {

    private WireMockServer wireMockServer;

    public StackOverflowTest() {
        super(MyApplication.class);
    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        wireMockServer = new WireMockServer(8080);
        wireMockServer.start();
        createApplication();
    }

    @Override
    protected void tearDown() throws Exception {
        wireMockServer.stop();
        super.tearDown();
    }
}

12-08 19:27:12.125 7680-7733/? D/org.eclipse.jetty.io.IdleTimeout: SelectChannelEndPoint@1a478f0{/127.0.0.1:50741<->8080,Open,in,out,R,-,29481/30000,FaultInjectingHttpConnection}{io=1,kio=1,kro=1} idle timeout check, elapsed: 29481 ms, remaining: 519 ms
12-08 19:27:12.645 7680-7733/? D/org.eclipse.jetty.io.IdleTimeout: SelectChannelEndPoint@1a478f0{/127.0.0.1:50741<->8080,Open,in,out,R,-,30001/30000,FaultInjectingHttpConnection}{io=1,kio=1,kro=1} idle timeout check, elapsed: 30001 ms, remaining: -1 ms
12-08 19:27:12.646 7680-7733/? D/org.eclipse.jetty.io.IdleTimeout: SelectChannelEndPoint@1a478f0{/127.0.0.1:50741<->8080,Open,in,out,R,-,30002/30000,FaultInjectingHttpConnection}{io=1,kio=1,kro=1} idle timeout expired
12-08 19:27:12.646 7680-7733/? D/org.eclipse.jetty.io.WriteFlusher: ignored: WriteFlusher@1d5f8c29{IDLE} java.util.concurrent.TimeoutException: Idle timeout expired: 30001/30000 ms
12-08 19:27:12.647 7680-7712/? D/org.eclipse.jetty.io.AbstractConnection: FILL_INTERESTED-->IDLE FaultInjectingHttpConnection@3ff0341c[IDLE,SelectChannelEndPoint@1a478f0{/127.0.0.1:50741<->8080,Open,in,out,-,-,30003/30000,FaultInjectingHttpConnection}{io=1,kio=1,kro=1}][p=HttpParser{s=START,0 of -1},g=HttpGenerator{s=START},c=HttpChannelOverHttp@18f210ee{r=5,c=false,a=IDLE,uri=}]
12-08 19:27:12.647 7680-7733/? D/org.eclipse.jetty.io.AbstractEndPoint: Ignored idle endpoint SelectChannelEndPoint@1a478f0{/127.0.0.1:50741<->8080,Open,in,out,-,-,30003/30000,FaultInjectingHttpConnection}{io=1,kio=1,kro=1}
12-08 19:27:12.647 7680-7712/? D/org.eclipse.jetty.http.HttpParser: close HttpParser{s=START,0 of -1}
12-08 19:27:12.648 7680-7712/? D/org.eclipse.jetty.http.HttpParser: START --> CLOSED
12-08 19:27:12.648 7680-7712/? D/org.eclipse.jetty.io.AbstractConnection: FaultInjectingHttpConnection@3ff0341c[IDLE,SelectChannelEndPoint@1a478f0{/127.0.0.1:50741<->8080,Open,in,out,-,-,1/30000,FaultInjectingHttpConnection}{io=1,kio=1,kro=1}][p=HttpParser{s=CLOSED,0 of -1},g=HttpGenerator{s=START},c=HttpChannelOverHttp@18f210ee{r=5,c=false,a=IDLE,uri=}] onFillInterestedFailed java.util.concurrent.TimeoutException: Idle timeout expired: 30001/30000 ms
12-08 19:27:12.648 7680-7712/? D/org.eclipse.jetty.io.ChannelEndPoint: oshut SelectChannelEndPoint@1a478f0{/127.0.0.1:50741<->8080,Open,in,out,-,-,1/30000,FaultInjectingHttpConnection}{io=1,kio=1,kro=1}
12-08 19:27:12.649 7680-7712/? D/org.eclipse.jetty.io.AbstractConnection: fillInterested FaultInjectingHttpConnection@3ff0341c[IDLE,SelectChannelEndPoint@1a478f0{/127.0.0.1:50741<->8080,Open,in,OSHUT,-,-,2/30000,FaultInjectingHttpConnection}{io=1,kio=1,kro=1}][p=HttpParser{s=CLOSED,0 of -1},g=HttpGenerator{s=START},c=HttpChannelOverHttp@18f210ee{r=5,c=false,a=IDLE,uri=}]
12-08 19:27:12.649 7680-7712/? D/org.eclipse.jetty.io.AbstractConnection: IDLE-->FILL_INTERESTED FaultInjectingHttpConnection@3ff0341c[FILL_INTERESTED,SelectChannelEndPoint@1a478f0{/127.0.0.1:50741<->8080,Open,in,OSHUT,-,-,2/30000,FaultInjectingHttpConnection}{io=1,kio=1,kro=1}][p=HttpParser{s=CLOSED,0 of -1},g=HttpGenerator{s=START},c=HttpChannelOverHttp@18f210ee{r=5,c=false,a=IDLE,uri=}]
12-08 19:27:12.650 7680-7712/? D/org.eclipse.jetty.io.SelectChannelEndPoint: Ignoring local interests update 1 -> 1 for SelectChannelEndPoint@1a478f0{/127.0.0.1:50741<->8080,Open,in,OSHUT,R,-,0/30000,FaultInjectingHttpConnection}{io=1,kio=1,kro=1}
12-08 19:27:42.649 7680-7733/? D/org.eclipse.jetty.io.IdleTimeout: SelectChannelEndPoint@1a478f0{/127.0.0.1:50741<->8080,Open,in,OSHUT,R,-,29999/30000,FaultInjectingHttpConnection}{io=1,kio=1,kro=1} idle timeout check, elapsed: 29999 ms, remaining: 1 ms
12-08 19:27:42.651 7680-7733/? D/org.eclipse.jetty.io.IdleTimeout: SelectChannelEndPoint@1a478f0{/127.0.0.1:50741<->8080,Open,in,OSHUT,R,-,30001/30000,FaultInjectingHttpConnection}{io=1,kio=1,kro=1} idle timeout check, elapsed: 30001 ms, remaining: -1 ms
12-08 19:27:42.651 7680-7733/? D/org.eclipse.jetty.io.IdleTimeout: SelectChannelEndPoint@1a478f0{/127.0.0.1:50741<->8080,Open,in,OSHUT,R,-,30001/30000,FaultInjectingHttpConnection}{io=1,kio=1,kro=1} idle timeout expired
12-08 19:27:42.652 7680-7733/? D/org.eclipse.jetty.io.WriteFlusher: ignored: WriteFlusher@1d5f8c29{IDLE} java.util.concurrent.TimeoutException: Idle timeout expired: 30001/30000 ms
12-08 19:27:42.652 7680-7714/? D/org.eclipse.jetty.io.AbstractConnection: FILL_INTERESTED-->IDLE FaultInjectingHttpConnection@3ff0341c[IDLE,SelectChannelEndPoint@1a478f0{/127.0.0.1:50741<->8080,Open,in,OSHUT,-,-,30002/30000,FaultInjectingHttpConnection}{io=1,kio=1,kro=1}][p=HttpParser{s=CLOSED,0 of -1},g=HttpGenerator{s=START},c=HttpChannelOverHttp@18f210ee{r=5,c=false,a=IDLE,uri=}]
12-08 19:27:42.652 7680-7733/? D/org.eclipse.jetty.io.AbstractEndPoint: Ignored idle endpoint SelectChannelEndPoint@1a478f0{/127.0.0.1:50741<->8080,Open,in,OSHUT,-,-,30002/30000,FaultInjectingHttpConnection}{io=1,kio=1,kro=1}
12-08 19:27:42.652 7680-7714/? D/org.eclipse.jetty.http.HttpParser: close HttpParser{s=CLOSED,0 of -1}
12-08 19:27:42.653 7680-7714/? D/org.eclipse.jetty.http.HttpParser: CLOSED --> CLOSED
12-08 19:27:42.653 7680-7714/? D/org.eclipse.jetty.io.AbstractConnection: FaultInjectingHttpConnection@3ff0341c[IDLE,SelectChannelEndPoint@1a478f0{/127.0.0.1:50741<->8080,Open,in,OSHUT,-,-,1/30000,FaultInjectingHttpConnection}{io=1,kio=1,kro=1}][p=HttpParser{s=CLOSED,0 of -1},g=HttpGenerator{s=START},c=HttpChannelOverHttp@18f210ee{r=5,c=false,a=IDLE,uri=}] onFillInterestedFailed java.util.concurrent.TimeoutException: Idle timeout expired: 30001/30000 ms
12-08 19:27:42.654 7680-7714/? D/org.eclipse.jetty.io.AbstractEndPoint: onClose SelectChannelEndPoint@1a478f0{/127.0.0.1:50741<->8080,CLOSED,in,OSHUT,-,-,2/30000,FaultInjectingHttpConnection}{io=1,kio=1,kro=1}
12-08 19:27:42.654 7680-7714/? D/org.eclipse.jetty.io.ChannelEndPoint: close SelectChannelEndPoint@1a478f0{/127.0.0.1:50741<->8080,CLOSED,in,OSHUT,-,-,2/30000,FaultInjectingHttpConnection}{io=1,kio=1,kro=1}
12-08 19:27:42.654 7680-7714/? D/org.eclipse.jetty.io.SelectorManager: Destroyed SelectChannelEndPoint@1a478f0{/127.0.0.1:50741<->8080,CLOSED,ISHUT,OSHUT,-,-,2/30000,FaultInjectingHttpConnection}{io=1,kio=-1,kro=-1}
12-08 19:27:42.655 7680-7707/? D/org.eclipse.jetty.io.SelectorManager: Selector loop woken up from select, 0/0 selected
12-08 19:27:42.655 7680-7698/? W/art: Long monitor contention event with owner method=int libcore.io.Posix.poll(android.system.StructPollfd[], int) from Posix.java:4294967294 waiters=0 for 59.925s
12-08 19:27:42.655 7680-7698/? D/org.eclipse.jetty.util.component.AbstractLifeCycle: stopping org.eclipse.jetty.io.SelectorManager$ManagedSelector@21c47df5 keys=0 selected=0
12-08 19:27:42.655 7680-7714/? D/org.eclipse.jetty.io.AbstractConnection: onClose FaultInjectingHttpConnection@3ff0341c[IDLE,SelectChannelEndPoint@1a478f0{/127.0.0.1:50741<->8080,CLOSED,ISHUT,OSHUT,-,-,3/30000,FaultInjectingHttpConnection}{io=1,kio=-1,kro=-1}][p=HttpParser{s=CLOSED,0 of -1},g=HttpGenerator{s=START},c=HttpChannelOverHttp@18f210ee{r=5,c=false,a=IDLE,uri=}]
12-08 19:27:42.655 7680-7707/? D/org.eclipse.jetty.io.SelectorManager: Selector loop waiting on select
12-08 19:27:42.656 7680-7698/? D/org.eclipse.jetty.io.SelectorManager: Stopping org.eclipse.jetty.io.SelectorManager$ManagedSelector@21c47df5 keys=0 selected=0
12-08 19:27:42.656 7680-7714/? D/org.eclipse.jetty.io.AbstractEndPoint: onClose SelectChannelEndPoint@1a478f0{/127.0.0.1:50741<->8080,CLOSED,ISHUT,OSHUT,-,-,4/30000,FaultInjectingHttpConnection}{io=1,kio=-1,kro=-1}
12-08 19:27:42.657 7680-7698/? D/org.eclipse.jetty.io.SelectorManager: Queued change org.eclipse.jetty.io.SelectorManager$ManagedSelector$Stop@b9ece89
12-08 19:27:42.657 7680-7707/? D/org.eclipse.jetty.io.SelectorManager: Selector loop woken up from select, 0/0 selected
12-08 19:27:42.657 7680-7707/? D/org.eclipse.jetty.io.SelectorManager: Running change org.eclipse.jetty.io.SelectorManager$ManagedSelector$Stop@b9ece89
12-08 19:27:42.658 7680-7698/? D/org.eclipse.jetty.io.SelectorManager: Stopped org.eclipse.jetty.io.SelectorManager$ManagedSelector@21c47df5 keys=-1 selected=-1
12-08 19:27:42.660 7680-7698/? D/org.eclipse.jetty.util.component.AbstractLifeCycle: STOPPED org.eclipse.jetty.io.SelectorManager$ManagedSelector@21c47df5 keys=-1 selected=-1
12-08 19:27:42.660 7680-7707/? D/org.eclipse.jetty.io.SelectorManager: Stopped Thread[qtp1052822663-321-selector-ServerConnectorManager@9d23a9b/0,5,main] on org.eclipse.jetty.io.SelectorManager$ManagedSelector@21c47df5 keys=-1 selected=-1

码头版本:

androidTestCompile "org.eclipse.jetty:jetty-server:9.2.14.v20151106"
androidTestCompile "org.eclipse.jetty:jetty-webapp:9.2.14.v20151106"
androidTestCompile "org.eclipse.jetty:jetty-servlet:9.2.14.v20151106"
androidTestCompile "org.eclipse.jetty:jetty-servlets:9.2.14.v20151106"
4

1 回答 1

1

Jetty 似乎正在尝试优雅地stop()等待所有活动连接和请求首先完成处理,然后才最终确定stop().

您的日志显示了许多TimeoutException事件,也许您应该查看这些并确保您正在正确处理您的 HTTP 交换(在客户端和服务器端)。根据您的日志,检查持久连接模式(注意您使用的 HTTP 版本),这些是最可能的原因。

于 2015-12-09T18:12:02.817 回答