Skip to content

Commit 5be8423

Browse files
committed
Improved broadcast test
1 parent bbe154b commit 5be8423

File tree

1 file changed

+43
-30
lines changed

1 file changed

+43
-30
lines changed

test/protocol/broadcast.js

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,59 +30,72 @@ test('BROADCAST TESTS', function(tt) {
3030
number: 1,
3131
subobject: {}
3232
}
33+
var objClient1 = {
34+
subobject: {
35+
broadcastFunction: function(a, b) {
36+
return a + b
37+
}
38+
}
39+
}
40+
var objClient2 = {
41+
subobject: {
42+
broadcastFunction: function(a, b) {
43+
return a * b
44+
}
45+
}
46+
}
47+
3348
dop.register(objServer)
34-
dop.setBroadcastFunction(objServer.subobject, 'broadcast')
49+
dop.setBroadcastFunction(objServer.subobject, 'broadcastFunction')
3550
dop.onSubscribe(function() {
3651
return objServer
3752
})
3853

39-
// setBroadcastFunction(object, 'namefunction')
54+
tt.equal(
55+
typeof objServer.subobject.broadcastFunction,
56+
'function',
57+
'broadcastFunction is a function'
58+
)
4059

4160
test('BROADCASTING TO CLIENTS', function(t) {
4261
client1
4362
.subscribe()
44-
.into({
45-
subobject: {
46-
broadcast: function(a, b) {
47-
return a + b
48-
}
49-
}
50-
})
63+
.into(objClient1)
5164
.then(function(obj) {
52-
return client2.subscribe().into({
53-
subobject: {
54-
broadcast: function(a, b) {
55-
return a * b
56-
}
57-
}
58-
})
65+
return client2.subscribe().into(objClient2)
5966
})
6067
.then(function(obj) {
61-
var promises = objServer.subobject.broadcast(2, 5)
68+
var promises = objServer.subobject.broadcastFunction(2, 5)
6269
t.equal(Array.isArray(promises), true, 'Promises is array')
6370
t.equal(promises.length, 2, 'Promises are two promises')
6471
t.equal(
6572
promises[0] instanceof Promise,
6673
true,
6774
'First promise is instanceof Promise'
6875
)
69-
Promise.all(promises).then(function(values) {
70-
t.equal(values[0], 7, 'First value must be 2+5=7')
71-
t.equal(values[0], 7, 'Second value must be 2*5=10')
72-
// try {
73-
server.listener.close()
74-
// client1.socket.close();
75-
// client2.socket.close();
76-
// } catch(e) {
77-
// console.log( e );
78-
// process.exit();
79-
// }
80-
t.end()
81-
})
76+
return Promise.all(promises)
8277
// .catch(function(err){
8378
// console.log( err );
8479
// })
8580
})
81+
.then(function(values) {
82+
t.equal(values[0], 7, 'First value must be 2+5=7')
83+
t.equal(values[1], 10, 'Second value must be 2*5=10')
84+
85+
objClient1.subobject.broadcastFunction = function(a, b) {
86+
return a / b
87+
}
88+
89+
return Promise.all(objServer.subobject.broadcastFunction(10, 2))
90+
})
91+
.then(function(values) {
92+
t.equal(values[0], 5, 'First value must be 10/2=5')
93+
t.equal(values[1], 20, 'Second value must be 10*2=20')
94+
server.listener.close()
95+
// client1.socket.close();
96+
// client2.socket.close();
97+
t.end()
98+
})
8699
})
87100

88101
// More test todo

0 commit comments

Comments
 (0)