test/test_backend.rb in polyphony-0.54.0 vs test/test_backend.rb in polyphony-0.55.0

- old
+ new

@@ -24,11 +24,11 @@ @backend.sleep 0.01 count += 1 @backend.sleep 0.01 count += 1 }.await - assert_in_delta 0.03, Time.now - t0, 0.005 + assert_in_delta 0.03, Time.now - t0, 0.01 assert_equal 3, count end def test_write_read_partial i, o = IO.pipe @@ -307,10 +307,40 @@ assert_equal 6, result o.close assert_equal 'hello world', i.read end + def test_simple_send_chain + port = rand(1234..5678) + server = TCPServer.new('127.0.0.1', port) + + server_fiber = spin do + while (socket = server.accept) + spin do + while (data = socket.gets(8192)) + socket << data + end + end + end + end + + snooze + client = TCPSocket.new('127.0.0.1', port) + + result = Thread.backend.chain( + [:send, client, 'hello', 0], + [:send, client, " world\n", 0] + ) + sleep 0.1 + assert_equal "hello world\n", client.recv(8192) + client.close + ensure + server_fiber&.stop + server_fiber&.await + server&.close + end + def chunk_header(len) "Content-Length: #{len}\r\n\r\n" end def serve_io(from, to) @@ -344,16 +374,30 @@ def test_invalid_op i, o = IO.pipe assert_raises(RuntimeError) { Thread.backend.chain( - [:read, o] + [:read, i] ) } assert_raises(RuntimeError) { Thread.backend.chain( + [:write, o, 'abc'], + [:write, o, 'abc'], + [:write, o, 'abc'], + [:read, i] + ) + } + + assert_raises(RuntimeError) { + Thread.backend.chain( [:write, o] ) } + + # Eventually we should add some APIs to the io_uring backend to query the + # contxt store, then add some tests here to verify that the chain op ctx is + # released properly before raising the error (for the time being this has + # been verified manually). end end