pass tape assertion helper to testscripts
This commit is contained in:
parent
48d7e92667
commit
4ccb342bff
|
@ -50,7 +50,7 @@ tape(testName, function (t) {
|
|||
sbot.conn.connect(to, (err, rpc) => {
|
||||
t.error(err, 'connected')
|
||||
t.comment('connected to: '+rpc.id)
|
||||
testSession.after(sbot, rpc, exit)
|
||||
testSession.after(t, sbot, rpc, exit)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -93,5 +93,5 @@ tape(testName, function (t) {
|
|||
t.comment('client spawned. I am:' + alice.id)
|
||||
|
||||
console.log(alice.id) // tell go process who's incoming
|
||||
testSession.before(sbot, ready)
|
||||
testSession.before(t, sbot, ready)
|
||||
})
|
||||
|
|
|
@ -5,7 +5,6 @@ const theStack = require('secret-stack')
|
|||
const ssbCaps = require('ssb-caps')
|
||||
|
||||
const testSHSappKey = bufFromEnv('TEST_APPKEY')
|
||||
|
||||
let testAppkey = Buffer.from(ssbCaps.shs, 'base64')
|
||||
if (testSHSappKey !== false) {
|
||||
testAppkey = testSHSappKey
|
||||
|
@ -26,7 +25,7 @@ for (plug of testSession.secretStackPlugins) {
|
|||
|
||||
tape.createStream().pipe(process.stderr);
|
||||
tape(testName, function (t) {
|
||||
// t.timeoutAfter(30000) // doesn't exit the process
|
||||
// t.timeoutAfter(30000) // doesn't exit the process
|
||||
// const tapeTimeout = setTimeout(() => {
|
||||
// t.comment("test timeout")
|
||||
// process.exit(1)
|
||||
|
@ -50,20 +49,17 @@ tape(testName, function (t) {
|
|||
})
|
||||
const alice = sbot.whoami()
|
||||
|
||||
// const replicate_changes = sbot.replicate.changes()
|
||||
|
||||
t.comment("sbot spawned, running before")
|
||||
|
||||
function ready() {
|
||||
t.comment('server spawned. I am:' + alice.id)
|
||||
console.log(alice.id) // tell go process who our pubkey
|
||||
}
|
||||
testSession.before(sbot, ready)
|
||||
|
||||
|
||||
testSession.before(t, sbot, ready)
|
||||
|
||||
sbot.on("rpc:connect", (remote, isClient) => {
|
||||
t.comment("new connection: "+ remote.id)
|
||||
testSession.after(sbot, remote, exit)
|
||||
testSession.after(t, sbot, remote, exit)
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
@ -3,11 +3,11 @@ const pull = require('pull-stream')
|
|||
module.exports = {
|
||||
secretStackPlugins: ['ssb-conn', 'ssb-room/tunnel/client'],
|
||||
|
||||
before: (sbot, ready) => {
|
||||
before: (t, sbot, ready) => {
|
||||
ready()
|
||||
},
|
||||
|
||||
after: (sbot, rpc, exit) => {
|
||||
after: (t, sbot, rpc, exit) => {
|
||||
sbot.on("rpc:connect", (remote, isClient) => {
|
||||
console.warn("tunneld connection to simple client!")
|
||||
|
||||
|
@ -19,8 +19,7 @@ module.exports = {
|
|||
console.warn('room left... exiting in 10s')
|
||||
setTimeout(exit, 10000)
|
||||
}).catch((err) => {
|
||||
console.warn('left failed')
|
||||
throw err
|
||||
t.error(err, 'tunnel.leave failed')
|
||||
})
|
||||
}, 3000)
|
||||
})
|
||||
|
@ -30,8 +29,7 @@ module.exports = {
|
|||
console.warn('announced!')
|
||||
console.warn(ret)
|
||||
}).catch((err) => {
|
||||
console.warn('announce failed')
|
||||
throw err
|
||||
t.error(err, 'tunnel.announce failed')
|
||||
})
|
||||
|
||||
// log all new endpoints
|
||||
|
|
|
@ -7,17 +7,18 @@ let newConnections = 0
|
|||
module.exports = {
|
||||
secretStackPlugins: ['ssb-conn', 'ssb-room/tunnel/client'],
|
||||
|
||||
before: (client, ready) => {
|
||||
before: (t, client, ready) => {
|
||||
// nothing to prepare (like publishes messages, or...)
|
||||
ready()
|
||||
},
|
||||
|
||||
after: (client, roomSrvRpc, exit) => {
|
||||
after: (t, client, roomSrvRpc, exit) => {
|
||||
newConnections++
|
||||
console.warn('new connection!', roomSrvRpc.id, 'total:', newConnections)
|
||||
t.comment('new connection!' + roomSrvRpc.id)
|
||||
t.comment('total connections:' + newConnections)
|
||||
|
||||
if (newConnections > 1) {
|
||||
console.warn('after call 2 - not exiting')
|
||||
t.comment('after call 2 - not exiting')
|
||||
return
|
||||
}
|
||||
// now connected to the room server
|
||||
|
@ -26,52 +27,49 @@ module.exports = {
|
|||
pull(
|
||||
roomSrvRpc.tunnel.endpoints(),
|
||||
pull.drain(el => {
|
||||
console.warn("from roomsrv:",el)
|
||||
t.comment("from roomsrv:",el)
|
||||
})
|
||||
)
|
||||
|
||||
roomSrvRpc.tunnel.isRoom().then((yes) => {
|
||||
if (!yes) throw new Error("expected isRoom to be true!")
|
||||
console.warn("peer is indeed a room!")
|
||||
t.equal(yes, true, "expected isRoom to return true!")
|
||||
|
||||
t.comment("peer is indeed a room!")
|
||||
|
||||
// announce ourselves to the room/tunnel
|
||||
roomSrvRpc.tunnel.announce().then((ret) => {
|
||||
console.warn('announced!')
|
||||
t.comment('announced!')
|
||||
|
||||
// put there by the go test process
|
||||
let roomHandle = readFileSync('endpoint_through_room.txt').toString()
|
||||
console.warn("connecting to room handle:", roomHandle)
|
||||
t.comment("connecting to room handle:", roomHandle)
|
||||
|
||||
client.conn.connect(roomHandle, (err, tunneldRpc) => {
|
||||
if (err) throw err
|
||||
console.warn("got tunnel to:", tunneldRpc.id)
|
||||
t.error(err, "connected")
|
||||
t.comment("got tunnel to:", tunneldRpc.id)
|
||||
|
||||
// check the tunnel connection works
|
||||
tunneldRpc.tunnel.ping((err, id) => {
|
||||
if (err) throw err
|
||||
console.warn("ping:", id)
|
||||
tunneldRpc.tunnel.ping((err, timestamp) => {
|
||||
t.error(err, "ping over the tunnel")
|
||||
t.comment("ping:"+timestamp)
|
||||
|
||||
// start leaving after 1s
|
||||
setTimeout(() => {
|
||||
roomSrvRpc.tunnel.leave().then((ret) => {
|
||||
console.warn('left room... exiting in 3s')
|
||||
t.comment('left room... exiting in 3s')
|
||||
setTimeout(exit, 3000)
|
||||
}).catch((err) => {
|
||||
console.warn('left failed')
|
||||
throw err
|
||||
t.error(err, 'leave')
|
||||
})
|
||||
}, 1000)
|
||||
})
|
||||
})
|
||||
|
||||
}).catch((err) => {
|
||||
console.warn('announce failed')
|
||||
throw err
|
||||
t.error(err, 'announce')
|
||||
})
|
||||
|
||||
}).catch((err) => {
|
||||
console.warn('isRoom failed')
|
||||
throw err
|
||||
t.error(err, 'isRoom failed')
|
||||
})
|
||||
}
|
||||
}
|
|
@ -5,22 +5,24 @@ let connections = 0
|
|||
module.exports = {
|
||||
secretStackPlugins: ['ssb-conn', 'ssb-room/tunnel/server'],
|
||||
|
||||
before: (sbot, ready) => {
|
||||
before: (t, sbot, ready) => {
|
||||
pull(
|
||||
sbot.conn.hub().listen(),
|
||||
pull.drain((p) => {
|
||||
console.warn('peer change:',p.type, p.key)
|
||||
t.comment(`peer change ${p.type}: ${p.key}`)
|
||||
})
|
||||
)
|
||||
setTimeout(ready, 1000)
|
||||
},
|
||||
|
||||
after: (sbot, client, exit) => {
|
||||
after: (t, sbot, client, exit) => {
|
||||
// this runs twice (for each connection)
|
||||
connections++
|
||||
console.warn('server new connection:', client.id, connections)
|
||||
t.comment(`server new connection: ${client.id}`)
|
||||
t.comment(`total connections: ${connections}`)
|
||||
|
||||
if (connections == 2) {
|
||||
t.comment('2nd connection received. exiting in 15 seconds')
|
||||
setTimeout(exit, 15000)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,11 +3,11 @@ const pull = require('pull-stream')
|
|||
module.exports = {
|
||||
secretStackPlugins: ['ssb-conn', 'ssb-room-client'],
|
||||
|
||||
before: (sbot, ready) => {
|
||||
before: (t, sbot, ready) => {
|
||||
ready()
|
||||
},
|
||||
|
||||
after: (sbot, rpc, exit) => {
|
||||
after: (t, sbot, rpc, exit) => {
|
||||
sbot.on("rpc:connect", (remote, isClient) => {
|
||||
console.warn("tunneld connection to simple client!")
|
||||
|
||||
|
|
|
@ -7,12 +7,12 @@ let newConnections = 0
|
|||
module.exports = {
|
||||
secretStackPlugins: ['ssb-conn', 'ssb-room-client'],
|
||||
|
||||
before: (client, ready) => {
|
||||
before: (t, client, ready) => {
|
||||
// nothing to prepare (like publishes messages, or...)
|
||||
ready()
|
||||
},
|
||||
|
||||
after: (client, roomSrvRpc, exit) => {
|
||||
after: (t, client, roomSrvRpc, exit) => {
|
||||
newConnections++
|
||||
console.warn('new connection!', roomSrvRpc.id, 'total:', newConnections)
|
||||
|
||||
|
|
|
@ -15,12 +15,18 @@ proably by turning the exported object into an init function which returns the {
|
|||
module.exports = {
|
||||
secretStackPlugins: ['ssb-blobs', 'ssb-what-ever-you-need'],
|
||||
|
||||
before: (sbot, ready) => {
|
||||
// t is the tape instance for assertions
|
||||
// sbot is the local sbot api
|
||||
// ready is a function to signal that preperation is done
|
||||
before: (t, sbot, ready) => {
|
||||
console.warn('before connect...')
|
||||
setTimeout(ready, 1000)
|
||||
},
|
||||
|
||||
after: (sbot, exit) => {
|
||||
// t and sbot are same as above
|
||||
// clientRpc is the muxrpc client to the other remote (i.e a rpc handle for the room the client is connected to)
|
||||
// exit() is a function that needs to be called to halt the process and exit (it also calls t.end())
|
||||
after: (t, sbot, clientRpc, exit) => {
|
||||
console.warn('after connect...')
|
||||
|
||||
setTimeout(exit, 5000)
|
||||
|
|
Loading…
Reference in New Issue