Branch
Hash :
ca63728c
Author :
Thomas de Grivel
Date :
2026-01-05T16:54:26
give more time to socket tests
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
require Facts
require File
require Socket
require Socket.Buf
require Socket.Facts
(r = fork()) ; void
if (r < 0) do
exit(1)
end
if r == 0 do
server_facts = Facts.database()
if File.exists?("server_test.facts") do
File.unlink("server_test.facts")
end
Facts.open(server_facts, "server_test.facts")
puts("server: listening on 15002")
server = Socket.listen("localhost", "15002")
if server.fd < 0 do
puts("server: listen failed")
exit_subprocess(1)
end
puts("server: waiting for connection")
if ! Socket.Facts.accept(server_facts, server) do
puts("server: accept failed")
exit_subprocess(1)
end
Socket.close(server)
puts("server: accepted connection, waiting for facts")
sleep(2)
puts("server: adding server fact")
Facts.add_tags(server_facts, :server, :says, :hello)
sleep(4)
Facts.with_tags(server_facts, ?, ?, ?, fn (fact) {
puts("server: received #{inspect(fact)}")
})
puts("server: OK")
Socket.Facts.close(server_facts)
Facts.delete(server_facts)
File.unlink("server_test.facts")
exit_subprocess(0)
else
sleep(1)
client_facts = Facts.database()
if File.exists?("client_test.facts") do
File.unlink("client_test.facts")
end
Facts.open(client_facts, "client_test.facts")
puts("client: connecting to 15002")
if ! Socket.Facts.open(client_facts, "localhost", "15002") do
puts("client: open failed")
exit(1)
end
sleep(1)
puts("client: adding fact")
Facts.add_tags(client_facts, :a, :b, :c)
sleep(4)
puts("client: checking for server facts")
Facts.with_tags(client_facts, ?, ?, ?, fn (fact) {
puts("client: has #{inspect(fact)}")
})
Socket.Facts.close(client_facts)
Facts.delete(client_facts)
File.unlink("client_test.facts")
puts("client: OK")
wait()
end
0