mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
test-cleancode: add the rest of vlib/x/websocket/
This commit is contained in:
@@ -1,38 +1,33 @@
|
||||
// use this test to test the websocket client in the autobahn test
|
||||
|
||||
module main
|
||||
|
||||
import x.websocket
|
||||
|
||||
fn main() {
|
||||
for i in 1 ..304 {
|
||||
for i in 1 .. 304 {
|
||||
println('\ncase: $i')
|
||||
handle_case(i) or {
|
||||
println('error should be ok: $err')
|
||||
}
|
||||
handle_case(i) or { println('error should be ok: $err') }
|
||||
}
|
||||
// update the reports
|
||||
uri := 'ws://autobahn_server:9001/updateReports?agent=v-client'
|
||||
mut ws := websocket.new_client(uri)?
|
||||
ws.connect()?
|
||||
ws.listen()?
|
||||
mut ws := websocket.new_client(uri) ?
|
||||
ws.connect() ?
|
||||
ws.listen() ?
|
||||
}
|
||||
|
||||
fn handle_case(case_nr int) ? {
|
||||
uri := 'ws://autobahn_server:9001/runCase?case=$case_nr&agent=v-client'
|
||||
mut ws := websocket.new_client(uri)?
|
||||
mut ws := websocket.new_client(uri) ?
|
||||
ws.on_message(on_message)
|
||||
ws.connect()?
|
||||
ws.listen()?
|
||||
ws.connect() ?
|
||||
ws.listen() ?
|
||||
}
|
||||
|
||||
fn on_message(mut ws websocket.Client, msg &websocket.Message)? {
|
||||
fn on_message(mut ws websocket.Client, msg &websocket.Message) ? {
|
||||
// autobahn tests expects to send same message back
|
||||
if msg.opcode == .pong {
|
||||
// We just wanna pass text and binary message back to autobahn
|
||||
return
|
||||
}
|
||||
ws.write(msg.payload, msg.opcode) or {
|
||||
panic(err)
|
||||
}
|
||||
ws.write(msg.payload, msg.opcode) or { panic(err) }
|
||||
}
|
||||
|
@@ -1,40 +1,35 @@
|
||||
// use this test to test the websocket client in the autobahn test
|
||||
|
||||
module main
|
||||
|
||||
import x.websocket
|
||||
|
||||
fn main() {
|
||||
for i in 1 ..304 {
|
||||
for i in 1 .. 304 {
|
||||
println('\ncase: $i')
|
||||
handle_case(i) or {
|
||||
println('error should be ok: $err')
|
||||
}
|
||||
handle_case(i) or { println('error should be ok: $err') }
|
||||
}
|
||||
// update the reports
|
||||
// uri := 'wss://localhost:9002/updateReports?agent=v-client'
|
||||
uri := 'wss://autobahn_server_wss:9002/updateReports?agent=v-client'
|
||||
mut ws := websocket.new_client(uri)?
|
||||
ws.connect()?
|
||||
ws.listen()?
|
||||
mut ws := websocket.new_client(uri) ?
|
||||
ws.connect() ?
|
||||
ws.listen() ?
|
||||
}
|
||||
|
||||
fn handle_case(case_nr int) ? {
|
||||
uri := 'wss://autobahn_server_wss:9002/runCase?case=$case_nr&agent=v-client'
|
||||
// uri := 'wss://localhost:9002/runCase?case=$case_nr&agent=v-client'
|
||||
mut ws := websocket.new_client(uri)?
|
||||
mut ws := websocket.new_client(uri) ?
|
||||
ws.on_message(on_message)
|
||||
ws.connect()?
|
||||
ws.listen()?
|
||||
ws.connect() ?
|
||||
ws.listen() ?
|
||||
}
|
||||
|
||||
fn on_message(mut ws websocket.Client, msg &websocket.Message)? {
|
||||
fn on_message(mut ws websocket.Client, msg &websocket.Message) ? {
|
||||
// autobahn tests expects to send same message back
|
||||
if msg.opcode == .pong {
|
||||
// We just wanna pass text and binary message back to autobahn
|
||||
return
|
||||
}
|
||||
ws.write(msg.payload, msg.opcode) or {
|
||||
panic(err)
|
||||
}
|
||||
ws.write(msg.payload, msg.opcode) or { panic(err) }
|
||||
}
|
||||
|
@@ -1,5 +1,4 @@
|
||||
// use this to test websocket server to the autobahn test
|
||||
|
||||
module main
|
||||
|
||||
import x.websocket
|
||||
@@ -12,19 +11,17 @@ fn main() {
|
||||
|
||||
fn handle_case(case_nr int) ? {
|
||||
uri := 'ws://localhost:9002/runCase?case=$case_nr&agent=v-client'
|
||||
mut ws := websocket.new_client(uri)?
|
||||
mut ws := websocket.new_client(uri) ?
|
||||
ws.on_message(on_message)
|
||||
ws.connect()?
|
||||
ws.listen()?
|
||||
ws.connect() ?
|
||||
ws.listen() ?
|
||||
}
|
||||
|
||||
fn on_message(mut ws websocket.Client, msg &websocket.Message)? {
|
||||
fn on_message(mut ws websocket.Client, msg &websocket.Message) ? {
|
||||
// autobahn tests expects to send same message back
|
||||
if msg.opcode == .pong {
|
||||
// We just wanna pass text and binary message back to autobahn
|
||||
return
|
||||
}
|
||||
ws.write(msg.payload, msg.opcode) or {
|
||||
panic(err)
|
||||
}
|
||||
ws.write(msg.payload, msg.opcode) or { panic(err) }
|
||||
}
|
||||
|
@@ -1,38 +1,33 @@
|
||||
// use this test to test the websocket client in the autobahn test
|
||||
|
||||
module main
|
||||
|
||||
import x.websocket
|
||||
|
||||
fn main() {
|
||||
for i in 1 ..304 {
|
||||
for i in 1 .. 304 {
|
||||
println('\ncase: $i')
|
||||
handle_case(i) or {
|
||||
println('error should be ok: $err')
|
||||
}
|
||||
handle_case(i) or { println('error should be ok: $err') }
|
||||
}
|
||||
// update the reports
|
||||
uri := 'ws://localhost:9001/updateReports?agent=v-client'
|
||||
mut ws := websocket.new_client(uri)?
|
||||
ws.connect()?
|
||||
ws.listen()?
|
||||
mut ws := websocket.new_client(uri) ?
|
||||
ws.connect() ?
|
||||
ws.listen() ?
|
||||
}
|
||||
|
||||
fn handle_case(case_nr int) ? {
|
||||
uri := 'ws://localhost:9001/runCase?case=$case_nr&agent=v-client'
|
||||
mut ws := websocket.new_client(uri)?
|
||||
mut ws := websocket.new_client(uri) ?
|
||||
ws.on_message(on_message)
|
||||
ws.connect()?
|
||||
ws.listen()?
|
||||
ws.connect() ?
|
||||
ws.listen() ?
|
||||
}
|
||||
|
||||
fn on_message(mut ws websocket.Client, msg &websocket.Message)? {
|
||||
fn on_message(mut ws websocket.Client, msg &websocket.Message) ? {
|
||||
// autobahn tests expects to send same message back
|
||||
if msg.opcode == .pong {
|
||||
// We just wanna pass text and binary message back to autobahn
|
||||
return
|
||||
}
|
||||
ws.write(msg.payload, msg.opcode) or {
|
||||
panic(err)
|
||||
}
|
||||
ws.write(msg.payload, msg.opcode) or { panic(err) }
|
||||
}
|
||||
|
@@ -1,40 +1,35 @@
|
||||
// use this test to test the websocket client in the autobahn test
|
||||
|
||||
module main
|
||||
|
||||
import x.websocket
|
||||
|
||||
fn main() {
|
||||
for i in 1 ..304 {
|
||||
for i in 1 .. 304 {
|
||||
println('\ncase: $i')
|
||||
handle_case(i) or {
|
||||
println('error should be ok: $err')
|
||||
}
|
||||
handle_case(i) or { println('error should be ok: $err') }
|
||||
}
|
||||
// update the reports
|
||||
// uri := 'wss://localhost:9002/updateReports?agent=v-client'
|
||||
uri := 'wss://autobahn_server_wss:9002/updateReports?agent=v-client'
|
||||
mut ws := websocket.new_client(uri)?
|
||||
ws.connect()?
|
||||
ws.listen()?
|
||||
mut ws := websocket.new_client(uri) ?
|
||||
ws.connect() ?
|
||||
ws.listen() ?
|
||||
}
|
||||
|
||||
fn handle_case(case_nr int) ? {
|
||||
uri := 'wss://autobahn_server_wss:9002/runCase?case=$case_nr&agent=v-client'
|
||||
// uri := 'wss://localhost:9002/runCase?case=$case_nr&agent=v-client'
|
||||
mut ws := websocket.new_client(uri)?
|
||||
mut ws := websocket.new_client(uri) ?
|
||||
ws.on_message(on_message)
|
||||
ws.connect()?
|
||||
ws.listen()?
|
||||
ws.connect() ?
|
||||
ws.listen() ?
|
||||
}
|
||||
|
||||
fn on_message(mut ws websocket.Client, msg &websocket.Message)? {
|
||||
fn on_message(mut ws websocket.Client, msg &websocket.Message) ? {
|
||||
// autobahn tests expects to send same message back
|
||||
if msg.opcode == .pong {
|
||||
// We just wanna pass text and binary message back to autobahn
|
||||
return
|
||||
}
|
||||
ws.write(msg.payload, msg.opcode) or {
|
||||
panic(err)
|
||||
}
|
||||
ws.write(msg.payload, msg.opcode) or { panic(err) }
|
||||
}
|
||||
|
Reference in New Issue
Block a user