diff options
author | Andrew Aladjev <aladjev.andrew@gmail.com> | 2021-09-05 05:42:08 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-05 11:42:08 +0900 |
commit | 261a0e0e4a3202ca004eddc3cc2cefc9e8d0a90a (patch) | |
tree | 312664812f7f0eccb2ff0694a16ca99fbd040e28 /test | |
parent | 8899fa0b3d41fd27dd1a2c6f75106cb78ff27236 (diff) |
Backport mutexes for socket and connection lists on win32 #4212 (#4218)
Co-authored-by: nagachika <nagachika@ruby-lang.org>
Diffstat (limited to 'test')
-rw-r--r-- | test/socket/test_tcp.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/test/socket/test_tcp.rb b/test/socket/test_tcp.rb index a9e2a417a5..b897ff5642 100644 --- a/test/socket/test_tcp.rb +++ b/test/socket/test_tcp.rb @@ -115,4 +115,29 @@ class TestSocket_TCPSocket < Test::Unit::TestCase assert_raise(IO::WaitReadable) { svr.accept_nonblock(exception: true) } } end + + def test_accept_multithread + attempts_count = 5 + server_threads_count = 3 + client_threads_count = 3 + + attempts_count.times do + server_threads = Array.new(server_threads_count) do + Thread.new do + TCPServer.open("localhost", 0) do |server| + accept_threads = Array.new(client_threads_count) do + Thread.new { server.accept.close } + end + client_threads = Array.new(client_threads_count) do + Thread.new { TCPSocket.open(server.addr[3], server.addr[1]) } + end + client_threads.each(&:join) + accept_threads.each(&:join) + end + end + end + + server_threads.each(&:join) + end + end end if defined?(TCPSocket) |