Skip to content

Commit

Permalink
add new unit tests and expand testing, fix makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Oberstein committed Mar 26, 2017
1 parent 9cf943b commit f10113a
Show file tree
Hide file tree
Showing 12 changed files with 156 additions and 51 deletions.
20 changes: 15 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,18 @@ default:

clean:
rm -rf build
rm -rf ./node_modules
rm -f .sconsign.dblite
#rm -rf ./node_modules
#rm -f .sconsign.dblite

requirements:
pip install scons boto taschenmesser
pip install -U scons boto taschenmesser
sudo apt install -y npm nodejs-legacy default-jre
node -v
sudo npm install -g google-closure-compiler nodeunit

browser_deps:
npm install
npm update

build: build_browser build_npm

Expand All @@ -27,11 +34,14 @@ build_npm:

publish: publish_browser publish_npm

publish_browser:
publish_browser: build_browser
scons publish

copy_browser: build_browser
git -C ../autobahn-js-built pull
cp ./build/* ../autobahn-js-built
@echo "Now commit and push autobahn-js-built!"
cp ./build/* ../crossbar/crossbar/templates/default/web/js/
@echo "Now commit and push these repos: autobahn-js-built, crossbar"

publish_npm:
npm publish
Expand Down
8 changes: 6 additions & 2 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ import pkg_resources

taschenmesser = pkg_resources.resource_filename('taschenmesser', '..')
#taschenmesser = "../../infrequent/taschenmesser"
ENV=os.environ

ENV['JS_COMPILER'] = '/usr/local/lib/node_modules/google-closure-compiler/compiler.jar'

env = Environment(tools = ['default', 'taschenmesser'],
toolpath = [taschenmesser],
ENV = os.environ)
ENV = ENV)

# Get package version
version = json.load(open('package.json'))['version']
Expand All @@ -23,7 +27,7 @@ sources = [os.path.join(sourcedir, d) for d in os.listdir(sourcedir)]
# browserified
ab = env.Command("build/autobahn.js",
"lib/autobahn.js",
"browserify $SOURCE --standalone autobahn -o $TARGET")
"/usr/local/lib/node_modules/browserify/bin/cmd.js $SOURCE --ignore-missing --standalone autobahn -o $TARGET")
Depends(ab, sources)

# minimized (with Google Closure)
Expand Down
10 changes: 7 additions & 3 deletions lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ Connection.prototype._create_transport = function () {
}
} catch (e) {
// ignore
log.debug("could not create WAMP transport '" + transport_factory.type + "': " + e);
log.warn("could not create WAMP transport '" + transport_factory.type + "': " + e);
}
}

// could not create any WAMP transport
log.warn('could not create any WAMP transport');
return null;
};

Expand Down Expand Up @@ -276,7 +276,11 @@ Connection.prototype.open = function () {
function retry () {

// create a WAMP transport
self._transport = self._create_transport();
try {
self._transport = self._create_transport();
} catch (e) {
console.log(e);
}

if (!self._transport) {
// failed to create a WAMP transport
Expand Down
3 changes: 3 additions & 0 deletions lib/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ if ('AUTOBAHN_DEBUG' in global && AUTOBAHN_DEBUG && 'console' in global) {
}
}

var warn = console.warn;

exports.debug = debug;
exports.warn = warn;
82 changes: 43 additions & 39 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,45 @@
{
"name": "autobahn",
"version": "0.11.2",
"description": "An implementation of The Web Application Messaging Protocol (WAMP).",
"main": "index.js",
"scripts": {
"test": "nodeunit test/test.js"
},
"dependencies": {
"crypto-js": ">= 3.1.8",
"tweetnacl": ">= 0.14.3",
"when": ">= 3.7.7",
"ws": ">= 1.1.1",
"msgpack-lite": ">= 0.1.26",
"int64-buffer": ">= 0.1.9"
},
"optionalDependencies": {
"bufferutil": ">= 1.2.1",
"utf-8-validate": ">= 1.2.1"
},
"devDependencies": {
"browserify": ">= 13.1.1",
"nodeunit": ">= 0.10.2"
},
"browser": {
"ws": false,
"lib/transport/rawsocket.js": false
},
"repository": {
"type": "git",
"url": "git://github.com/crossbario/autobahn-js.git"
},
"keywords": [
"WAMP",
"WebSocket",
"RPC",
"PubSub"
],
"author": "Crossbar.io Technologies GmbH",
"license": "MIT"
"name": "autobahn",
"version": "0.12.0",
"description": "An implementation of The Web Application Messaging Protocol (WAMP).",
"main": "index.js",
"scripts": {
"test": "nodeunit test/test.js"
},
"engines": {
"node": ">= 4.2.6"
},
"dependencies": {
"crypto-js": ">= 3.1.8",
"google-closure-compiler": "^20170218.0.0",
"int64-buffer": ">= 0.1.9",
"msgpack-lite": ">= 0.1.26",
"tweetnacl": ">= 0.14.3",
"when": ">= 3.7.7",
"ws": "< 2.0.0"
},
"optionalDependencies": {
"bufferutil": ">= 1.2.1",
"utf-8-validate": ">= 1.2.1"
},
"devDependencies": {
"browserify": ">= 13.1.1",
"nodeunit": ">= 0.10.2"
},
"browser": {
"ws": false,
"lib/transport/rawsocket.js": false
},
"repository": {
"type": "git",
"url": "git://github.com/crossbario/autobahn-js.git"
},
"keywords": [
"WAMP",
"WebSocket",
"RPC",
"PubSub"
],
"author": "Crossbar.io Technologies GmbH",
"license": "MIT"
}
5 changes: 5 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

// this works via https://github.com/caolan/nodeunit

var sync = require('./test_basic_sync.js');
var async = require('./test_basic_async.js');
var connect = require('./test_connect.js');
var msgpack_serialization = require('./test_msgpack_serialization.js');
var rpc_complex = require('./test_rpc_complex.js');
Expand All @@ -32,6 +34,8 @@ var pubsub_prefix_sub = require('./test_pubsub_prefix_sub.js');
var pubsub_wildcard_sub = require('./test_pubsub_wildcard_sub.js');


exports.testSync = sync.testSync;
exports.testAsync = async.testAsync;
exports.testConnect = connect.testConnect;
exports.testMsgpackSerialization = msgpack_serialization.testMsgpackSerialization;
exports.testRpcArguments = rpc_arguments.testRpcArguments;
Expand All @@ -46,6 +50,7 @@ exports.testPubsubComplex = pubsub_complex.testPubsubComplex;
exports.testPubsubOptions = pubsub_options.testPubsubOptions;
exports.testPubsubExcludeMe = pubsub_excludme.testPubsubExcludeMe;
exports.testPubsubExclude = pubsub_exclude.testPubsubExclude;
exports.testPubsubEligible = pubsub_eligible.testPubsubEligible;
exports.testPubsubPrefixSub = pubsub_prefix_sub.testPubsubPrefixSub;
exports.testPubsubWildcardSub = pubsub_wildcard_sub.testPubsubWildcardSub;

41 changes: 41 additions & 0 deletions test/test_basic_async.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
///////////////////////////////////////////////////////////////////////////////
//
// AutobahnJS - http://autobahn.ws, http://wamp.ws
//
// A JavaScript library for WAMP ("The Web Application Messaging Protocol").
//
// Copyright (c) Crossbar.io Technologies GmbH and contributors
//
// Licensed under the MIT License.
// http://www.opensource.org/licenses/mit-license.php
//
///////////////////////////////////////////////////////////////////////////////

var autobahn = require('./../index.js');
var testutil = require('./testutil.js');

exports.testAsync = function (testcase) {

testcase.expect(1);

var test = new testutil.Testlog("test/test_basic_async.txt");

var d1 = autobahn.when.defer();
var d2 = autobahn.when.defer();

var df = autobahn.when.all([d1.promise, d2.promise]).then(
function (res) {
test.log(res);
var chk = test.check();
testcase.ok(!chk, chk);
testcase.done();
},
function (err) {
test.log(err);
testcase.done();
}
);

d1.resolve(23);
d2.resolve(42);
}
1 change: 1 addition & 0 deletions test/test_basic_async.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0 [23,42]
27 changes: 27 additions & 0 deletions test/test_basic_sync.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
///////////////////////////////////////////////////////////////////////////////
//
// AutobahnJS - http://autobahn.ws, http://wamp.ws
//
// A JavaScript library for WAMP ("The Web Application Messaging Protocol").
//
// Copyright (c) Crossbar.io Technologies GmbH and contributors
//
// Licensed under the MIT License.
// http://www.opensource.org/licenses/mit-license.php
//
///////////////////////////////////////////////////////////////////////////////

var autobahn = require('./../index.js');
var testutil = require('./testutil.js');

exports.testSync = function (testcase) {

testcase.expect(1);

var test = new testutil.Testlog("test/test_basic_sync.txt");

test.log(true);
var chk = test.check();
testcase.ok(!chk, chk);
testcase.done();
}
1 change: 1 addition & 0 deletions test/test_basic_sync.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0 true
4 changes: 2 additions & 2 deletions test/test_connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
var autobahn = require('./../index.js');
var testutil = require('./testutil.js');


exports.testConnect = function (testcase) {

testcase.expect(1);
Expand All @@ -35,12 +34,13 @@ exports.testConnect = function (testcase) {
res[i].leave();
}

var chk = test.check()
var chk = test.check();
testcase.ok(!chk, chk);
testcase.done();
},
function (err) {
test.log(err);
testcase.done();
}
);
}
5 changes: 5 additions & 0 deletions test/testutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ function connect_n(n) {
d.resolve(session);
};

connection.onclose = function (reason, details) {
console.log('CLOSE', reason, details);
}

connection.open();

dl.push(d.promise);
Expand All @@ -60,6 +64,7 @@ var Testlog = function (filename) {

self._filename = filename;
self._log = [];
// self._log = [["AutobahnJS " + autobahn.version]];
};


Expand Down

0 comments on commit f10113a

Please sign in to comment.