Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Oberstein committed Apr 19, 2014
1 parent f168dd5 commit 9830a6e
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 1 deletion.
4 changes: 4 additions & 0 deletions package/test/test.js
Expand Up @@ -21,6 +21,8 @@ var rpc_progress = require('./test_rpc_progress.js');
var rpc_slowsquare = require('./test_rpc_slowsquare.js');
var rpc_routing = require('./test_rpc_routing.js');
var pubsub_basic = require('./test_pubsub_basic.js');
var pubsub_complex = require('./test_pubsub_complex.js');
var pubsub_options = require('./test_pubsub_options.js');

exports.testRpcArguments = rpc_arguments.testRpcArguments;
exports.testRpcComplex = rpc_complex.testRpcComplex;
Expand All @@ -30,3 +32,5 @@ exports.testRpcProgress = rpc_progress.testRpcProgress;
exports.testRpcSlowsquare = rpc_slowsquare.testRpcSlowsquare;
exports.testRpcRouting = rpc_routing.testRpcRouting;
exports.testPubsubBasic = pubsub_basic.testPubsubBasic;
exports.testPubsubComplex = pubsub_complex.testPubsubComplex;
exports.testPubsubOptions = pubsub_options.testPubsubOptions;
81 changes: 81 additions & 0 deletions package/test/test_pubsub_complex.js
@@ -0,0 +1,81 @@
///////////////////////////////////////////////////////////////////////////////
//
// 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.testPubsubComplex = function (testcase) {

testcase.expect(1);

var test = new testutil.Testlog("test/test_pubsub_complex.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 () {
var lst = [];
for (var i = 0; i < counter; ++i) {
lst.push(i);
}
var obj = {
'counter': counter,
'foo': [1, counter, 2 * counter],
'bar': 'This is a test text.',
'baz': {
'a': 1.23456, 'b': 10000, 'c': null, 'd': 'foo'
}
};
session1.publish('com.myapp.topic1', lst, obj);

counter += 1;

test.log("events published", counter);
}, 1000);


var received = 0;

function on_topic1(args, kwargs) {
test.log("got event:", args, kwargs);
received += 1;
if (received > 5) {
test.log("closing ..");

clearInterval(t1);

session1.leave();
session2.leave();

var chk = test.check()
testcase.ok(!chk, chk);
testcase.done();
}
}

session2.subscribe('com.myapp.topic1', on_topic1);
},
function (err) {
test.log(err);
}
);
}
14 changes: 14 additions & 0 deletions package/test/test_pubsub_complex.txt
@@ -0,0 +1,14 @@
0 "all sessions connected"
1 "events published" 1
2 "got event:" [] {"baz":{"a":1.23456,"c":null,"b":10000,"d":"foo"},"counter":0,"bar":"This is a test text.","foo":[1,0,0]}
3 "events published" 2
4 "got event:" [0] {"baz":{"a":1.23456,"c":null,"b":10000,"d":"foo"},"counter":1,"bar":"This is a test text.","foo":[1,1,2]}
5 "events published" 3
6 "got event:" [0,1] {"baz":{"a":1.23456,"c":null,"b":10000,"d":"foo"},"counter":2,"bar":"This is a test text.","foo":[1,2,4]}
7 "events published" 4
8 "got event:" [0,1,2] {"baz":{"a":1.23456,"c":null,"b":10000,"d":"foo"},"counter":3,"bar":"This is a test text.","foo":[1,3,6]}
9 "events published" 5
10 "got event:" [0,1,2,3] {"baz":{"a":1.23456,"c":null,"b":10000,"d":"foo"},"counter":4,"bar":"This is a test text.","foo":[1,4,8]}
11 "events published" 6
12 "got event:" [0,1,2,3,4] {"baz":{"a":1.23456,"c":null,"b":10000,"d":"foo"},"counter":5,"bar":"This is a test text.","foo":[1,5,10]}
13 "closing .."
74 changes: 74 additions & 0 deletions package/test/test_pubsub_options.js
@@ -0,0 +1,74 @@
///////////////////////////////////////////////////////////////////////////////
//
// 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.testPubsubOptions = function (testcase) {

testcase.expect(1);

var test = new testutil.Testlog("test/test_pubsub_options.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 () {
var options = {acknowledge: true, disclose_me: true};

session1.publish('com.myapp.topic1', [counter], {}, options).then(
function (pub) {
test.log("event published", typeof(pub), typeof(pub.id));
}
);
counter += 1;
}, 1000);

var received = 0;

var sub;

function onevent1(args, kwargs, details) {
test.log("got event:", typeof(details), typeof(details.publication), typeof(details.publisher), details.publisher == session1.id, 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);
}
);
}
14 changes: 14 additions & 0 deletions package/test/test_pubsub_options.txt
@@ -0,0 +1,14 @@
0 "all sessions connected"
1 "event published" "object" "number"
2 "got event:" "object" "number" "number" true 0
3 "event published" "object" "number"
4 "got event:" "object" "number" "number" true 1
5 "event published" "object" "number"
6 "got event:" "object" "number" "number" true 2
7 "event published" "object" "number"
8 "got event:" "object" "number" "number" true 3
9 "event published" "object" "number"
10 "got event:" "object" "number" "number" true 4
11 "event published" "object" "number"
12 "got event:" "object" "number" "number" true 5
13 "Closing .."
2 changes: 1 addition & 1 deletion package/test/testutil.js
Expand Up @@ -54,7 +54,7 @@ Testlog.prototype.log = function () {

var self = this;

console.log.apply(this, arguments);
//console.log.apply(this, arguments);
self._log.push(arguments);
};

Expand Down

0 comments on commit 9830a6e

Please sign in to comment.