mirror of
https://github.com/lune-org/lune.git
synced 2025-05-04 10:43:57 +01:00
implement 'wss-rw' luau test to ensure we can read and write to sockets
This commit is contained in:
parent
e5a844ecec
commit
2ac5a0380d
1 changed files with 26 additions and 0 deletions
26
tests/net/socket/wss-rw.luau
Normal file
26
tests/net/socket/wss-rw.luau
Normal file
|
@ -0,0 +1,26 @@
|
|||
local net = require("@lune/net")
|
||||
local process = require("@lune/process")
|
||||
local task = require("@lune/task")
|
||||
|
||||
-- We're going to use Discord's WebSocket gateway server
|
||||
-- for testing that we can both read from a stream,
|
||||
-- as well as write to the same stream concurrently
|
||||
local socket = net.socket("wss://gateway.discord.gg/?v=10&encoding=json")
|
||||
|
||||
task.spawn(function()
|
||||
while not socket.closeCode do
|
||||
socket.next()
|
||||
end
|
||||
end)
|
||||
|
||||
task.delay(1, function()
|
||||
socket.send('{"op":1,"d":null}')
|
||||
socket.close(1000)
|
||||
|
||||
process.exit(1)
|
||||
end)
|
||||
|
||||
task.wait(5)
|
||||
|
||||
task.defer(process.exit, 1)
|
||||
error("`socket.send` halted, failed to write to socket")
|
Loading…
Add table
Reference in a new issue