refactor opening tunnel test, cleanup test comments
This commit is contained in:
parent
5b8b1af96a
commit
f15a5b2f11
|
@ -45,7 +45,7 @@ tape(testName, function (t) {
|
|||
function ready() { // needs to be called by the before block when it's done
|
||||
t.timeoutAfter(timeoutLength) // doesn't exit the process
|
||||
tapeTimeout = setTimeout(() => {
|
||||
t.comment('test timeout')
|
||||
t.comment('!! test did not complete before timeout; shutting everything down')
|
||||
process.exit(1)
|
||||
}, timeoutLength)
|
||||
const to = `net:${testPeerAddr}~shs:${testPeerRef.substr(1).replace('.ed25519', '')}`
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
const pull = require('pull-stream')
|
||||
const { readFileSync } = require('fs')
|
||||
|
||||
let newConnections = 0
|
||||
|
||||
module.exports = (t, client, roomrpc, exit) => {
|
||||
newConnections++
|
||||
t.comment('client new connection!' + roomrpc.id)
|
||||
t.comment('total connections:' + newConnections)
|
||||
|
||||
if (newConnections > 1) {
|
||||
t.comment('after call 2 - not doing anything')
|
||||
return
|
||||
}
|
||||
|
||||
// we are now connected to the room server.
|
||||
// log all new endpoints
|
||||
pull(
|
||||
roomrpc.tunnel.endpoints(),
|
||||
pull.drain(el => {
|
||||
t.comment("from roomsrv:" + JSON.stringify(el))
|
||||
})
|
||||
)
|
||||
|
||||
// give the room time to start
|
||||
setTimeout(() => {
|
||||
// announce ourselves to the room/tunnel
|
||||
roomrpc.tunnel.announce((err, ret) => {
|
||||
t.error(err, 'announce on server')
|
||||
t.comment('announced!')
|
||||
|
||||
// put there by the go test process
|
||||
let roomHandle = readFileSync('endpoint_through_room.txt').toString()
|
||||
t.comment("connecting to room handle:", roomHandle)
|
||||
|
||||
client.conn.connect(roomHandle, (err, tunneledrpc) => {
|
||||
t.error(err, 'connect through room')
|
||||
t.comment("got tunnel to:", tunneledrpc.id)
|
||||
|
||||
// check the tunnel connection works
|
||||
tunneledrpc.testing.working((err, ok) => {
|
||||
t.error(err, 'testing.working didnt error')
|
||||
t.true(ok, 'testing.working is true')
|
||||
|
||||
// start leaving after 2s
|
||||
setTimeout(() => {
|
||||
roomrpc.tunnel.leave((err, ret) => {
|
||||
t.error(err, 'tunnel.leave')
|
||||
t.comment('left room... exiting in 3s')
|
||||
setTimeout(exit, 3000)
|
||||
})
|
||||
}, 2000)
|
||||
})
|
||||
})
|
||||
})
|
||||
}, 5000)
|
||||
}
|
|
@ -1,38 +1,38 @@
|
|||
const pull = require('pull-stream')
|
||||
|
||||
module.exports = (t, sbot, rpc, exit) => {
|
||||
// this waits for a new incomming connection _after_ the room server is connected already
|
||||
// this waits for a new incoming connection _after_ the room server is connected already
|
||||
// so it will be an incomming tunnel client.
|
||||
// since this calls exit() - if no client connects it will not exit
|
||||
sbot.on("rpc:connect", (remote, isClient) => {
|
||||
console.warn("tunneled connection to simple client!")
|
||||
t.comment("tunneled connection to simple client!")
|
||||
|
||||
// leave after 3 seconds (give the other party time to call ping)
|
||||
// leave after 3 seconds (give the other party time to call `testing.working()`)
|
||||
setTimeout(() => {
|
||||
rpc.tunnel.leave().then((ret) => {
|
||||
console.warn('left')
|
||||
console.warn(ret)
|
||||
console.warn('room left... exiting in 1s')
|
||||
rpc.tunnel.leave((err, ret) => {
|
||||
t.error(err, 'tunnel.leave')
|
||||
t.comment(`tunnel error: ${err}`)
|
||||
t.comment(`leave value: ${ret}`)
|
||||
t.comment('left')
|
||||
t.comment('room left... exiting in 1s')
|
||||
setTimeout(exit, 1000)
|
||||
}).catch((err) => {
|
||||
t.error(err, 'tunnel.leave failed')
|
||||
})
|
||||
}, 3000)
|
||||
})
|
||||
|
||||
// announce ourselves to the room/tunnel
|
||||
rpc.tunnel.announce().then((ret) => {
|
||||
console.warn('announced!')
|
||||
console.warn(ret)
|
||||
}).catch((err) => {
|
||||
t.error(err, 'tunnel.announce failed')
|
||||
rpc.tunnel.announce((err, ret) => {
|
||||
t.error(err, 'tunnel.announce')
|
||||
t.comment(`announce error: ${err}`)
|
||||
t.comment(`announce value: ${ret}`)
|
||||
t.comment('announced!')
|
||||
})
|
||||
|
||||
// log all new endpoints
|
||||
pull(
|
||||
rpc.tunnel.endpoints(),
|
||||
pull.drain(el => {
|
||||
console.warn("from roomsrv:",el)
|
||||
t.comment("from roomsrv:",el)
|
||||
})
|
||||
)
|
||||
}
|
||||
|
|
|
@ -22,8 +22,8 @@ module.exports = {
|
|||
t.comment(`total connections: ${connections}`)
|
||||
|
||||
if (connections == 2) {
|
||||
t.comment('2nd connection received. exiting in 10 seconds')
|
||||
setTimeout(exit, 10000)
|
||||
t.comment('2nd connection received. exiting in 20 seconds')
|
||||
setTimeout(exit, 20000)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue