Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tobias Oberstein
committed
Apr 19, 2014
1 parent
4961df1
commit f168dd5
Showing
3 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// AutobahnJS - http://autobahn.ws, http://wamp.ws | ||
// | ||
// A JavaScript library for WAMP ("The Web Application Messaging Protocol"). | ||
// | ||
// Copyright (C) 2011-2014 Tavendo GmbH, http://tavendo.com | ||
// | ||
// Licensed under the MIT License. | ||
// http://www.opensource.org/licenses/mit-license.php | ||
// | ||
/////////////////////////////////////////////////////////////////////////////// | ||
|
||
var autobahn = require('./../index.js'); | ||
var testutil = require('./testutil.js'); | ||
|
||
|
||
exports.testPubsubBasic = function (testcase) { | ||
|
||
testcase.expect(1); | ||
|
||
var test = new testutil.Testlog("test/test_pubsub_basic.txt"); | ||
|
||
var dl = testutil.connect_n(2); | ||
|
||
autobahn.when.all(dl).then( | ||
function (res) { | ||
test.log("all sessions connected"); | ||
|
||
var session1 = res[0]; | ||
var session2 = res[1]; | ||
|
||
var counter = 0; | ||
|
||
var t1 = setInterval(function () { | ||
test.log("publishing to topic 'com.myapp.topic1': " + counter); | ||
session1.publish('com.myapp.topic1', [counter]); | ||
counter += 1; | ||
}, 1000); | ||
|
||
var received = 0; | ||
|
||
var sub; | ||
function onevent1(args) { | ||
test.log("Got event:", args[0]); | ||
received += 1; | ||
if (received > 5) { | ||
test.log("Closing .."); | ||
|
||
clearInterval(t1); | ||
|
||
session1.leave(); | ||
session2.leave(); | ||
|
||
var chk = test.check() | ||
testcase.ok(!chk, chk); | ||
testcase.done(); | ||
} | ||
} | ||
|
||
sub = session2.subscribe('com.myapp.topic1', onevent1); | ||
}, | ||
function (err) { | ||
test.log(err); | ||
} | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
0 "all sessions connected" | ||
1 "publishing to topic 'com.myapp.topic1': 0" | ||
2 "Got event:" 0 | ||
3 "publishing to topic 'com.myapp.topic1': 1" | ||
4 "Got event:" 1 | ||
5 "publishing to topic 'com.myapp.topic1': 2" | ||
6 "Got event:" 2 | ||
7 "publishing to topic 'com.myapp.topic1': 3" | ||
8 "Got event:" 3 | ||
9 "publishing to topic 'com.myapp.topic1': 4" | ||
10 "Got event:" 4 | ||
11 "publishing to topic 'com.myapp.topic1': 5" | ||
12 "Got event:" 5 | ||
13 "Closing .." |