refactor 'wss-rw' into a functional test for lune cargo tests

This commit is contained in:
AsynchronousMatrix 2023-07-19 18:08:56 +01:00
parent 2ac5a0380d
commit ee6fd5d886

View file

@ -7,20 +7,23 @@ local task = require("@lune/task")
-- as well as write to the same stream concurrently -- as well as write to the same stream concurrently
local socket = net.socket("wss://gateway.discord.gg/?v=10&encoding=json") local socket = net.socket("wss://gateway.discord.gg/?v=10&encoding=json")
task.spawn(function() local spawnedThread = task.spawn(function()
while not socket.closeCode do while not socket.closeCode do
socket.next() socket.next()
end end
end) end)
task.delay(1, function() local delayedThread = task.delay(5, function()
socket.send('{"op":1,"d":null}') task.defer(process.exit, 1)
socket.close(1000) error("`socket.send` halted, failed to write to socket")
process.exit(1) process.exit(1)
end) end)
task.wait(5) task.wait(1)
task.defer(process.exit, 1) socket.send('{"op":1,"d":null}')
error("`socket.send` halted, failed to write to socket") socket.close(1000)
task.cancel(delayedThread)
task.cancel(spawnedThread)