diff --git a/dev/tests/network.lua b/dev/tests/network.lua index 36f41b62..5edbe012 100644 --- a/dev/tests/network.lua +++ b/dev/tests/network.lua @@ -1,4 +1,5 @@ for i=1,3 do + print(string.format("iteration %s", i + 1)) local text = "" local complete = false @@ -7,32 +8,38 @@ for i=1,3 do end local server = network.tcp_open(7645, function (client) + print("client connected") start_coroutine(function() + print("client-listener started") local received_text = "" - while client:is_alive() do + while client:is_alive() and #received_text < #text do local received = client:recv(512) if received then received_text = received_text .. utf8.tostring(received) + print(string.format("received %s byte(s) from client", #received)) end coroutine.yield() end - assert (received_text == text) + asserts.equals (text, received_text) complete = true end, "client-listener") end) network.tcp_connect("localhost", 7645, function (socket) + print("connected to server") start_coroutine(function() + print("data-sender started") local ptr = 1 - while ptr < #text do + while ptr <= #text do local n = math.random(1, 20) socket:send(string.sub(text, ptr, ptr + n - 1)) + print(string.format("sent %s byte(s) to server", n)) ptr = ptr + n end socket:close() end, "data-sender") end) - app.sleep_until(function () return complete end) + app.sleep_until(function () return complete end, 1000000) server:close() end