确保在自动化测试的上下文中可供收听TCP端口?
我们有一些集成测试将启动HTTP服务器进程,验证呼叫,停止(或杀死)服务器,RINSE&重复。
这些测试的重点是它们在完整的客户端-TCP-HTTP-Server堆栈上端到端运行。我们必须重新启动服务器,因为我们需要测试多个配置选项。
现在,在Windows上自动运行它们时的问题是,有时(1/10?1/20?...)重新启动服务器会失败,
System.ServiceModel.AddressAlreadyInUseException: Für den IP-Endpunkt 0.0.0.0:59951 ist bereits ein Listener vorhanden.
因为端口尚未可供收听(尚未?)。
过去,我们通过在再次启动服务器之前添加多秒延迟来取得了一些成功,但这似乎是如此笨拙。
请注意,服务器并不总是优雅地关闭,因为测试案例需要有力的终止,或者是因为从驱动程序脚本到仅终止服务器的程序更容易。 无论如何 - 由于该过程“拥有”插座已死,因此该过程将在过程结束后不久就可以使用,但是它不清楚这可以花费多长时间或如何测试。
- 如何启动服务器的脚本确保如果服务器要绑定到的端点是否可用?
- 另外:如果服务器代码无法绑定到端点,那么服务器代码是否有一个有用的策略?
- 如果我们要添加一个延迟,这应该多长时间?
We have some integration tests that will start an HTTP server process, verify calls, stop (or kill) server, rinse & repeat.
The whole point of these tests is that they run end-to-end over the full client-tcp-http-server stack. And we have to restart the server because we need to test multiple configuration options.
Now, the problem when running these automatically on Windows is that sometimes (1/10? 1/20? ...) re-starting the server will fail with
System.ServiceModel.AddressAlreadyInUseException: Für den IP-Endpunkt 0.0.0.0:59951 ist bereits ein Listener vorhanden.
because the port is not available for listen (yet?).
We had some success in the past by adding multi-second delays before starting the server again, but this seems so clunky.
Please note that the server is not always gracefully shut down, either because the test case requires forceful termination or because its just easier from the driver script to just TerminateProcess the server.
Anyhow - since the process "owning" the socket is dead, it will be available shortly after process end, but its unclear how long this can take or how to test it.
- How can the script that will start the server make sure iff the endpoint that the server is going to bind to is available?
- Alternatively: Is there a useful strategy for the server code to try to recover/retry if it cannot bind to an endpoint?
- Ifff we were to add a delay, how long should this be?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论