Skip to content
This repository was archived by the owner on Jan 15, 2021. It is now read-only.

Commit ab57348

Browse files
committed
Merge pull request #453 from thaliproject/issue_171
Wifi-based mocks for the current version
2 parents dcd4242 + 70bee58 commit ab57348

30 files changed

+843
-290
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,17 @@ gradlew.bat
1212
# Nodejs
1313
node_modules
1414
npm-debug.log
15+
1516
# Cordova
1617
out/
1718

1819
# VS Code
1920
.settings/
21+
.vscode/
2022

2123
# Testing
2224
test/TestServer/server-address.js
2325
test/www/jxcore/server-address.js
26+
27+
# Misc
28+
thali/readme.md

build.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ fi
4848
thali/install/setUpDesktop.sh;ERROR_ABORT
4949
cd test/www/jxcore/;ERROR_ABORT
5050
jx npm test;ERROR_ABORT
51+
jx npm run test-meta;ERROR_ABORT
52+
# Disabled coordinated tests since there was some
53+
# issue with them in the CI.
54+
#jx npm run test-coordinated;ERROR_ABORT
5155
# Make sure we are back in the project root folder
5256
# after the test execution
5357
cd $PROJECT_ROOT;ERROR_ABORT

mobile_test.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"android": "com.test.thalitest",
1111
"ios": "com.test.thalitest"
1212
},
13-
"timeout": 1800,
13+
"timeout": 1200,
1414
"serverScript": "test/TestServer/"
1515
}
1616

test/README.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,23 @@ environment.
6767
All of the tests are designed to be run on the desktop. Tests that require the ThaliEmitter (our mobile environment)
6868
will de-activate themselves when run on the desktop. What is especially nice about running on the desktop is that
6969
one can develop and debug directly in the Thali_CordovaPlugin directory. There is no need to do the kind of
70-
copying and pasting that Cordova development normally requires. Note that only the unit tests run on the desktop.
71-
The perf tests are focused exclusively on measuring on the wire perf and so don't make sense (yet) on the desktop.
70+
copying and pasting that Cordova development normally requires.
7271

7372
To set up your desktop environment for development go to Thali_CordovaPlugin/thali/install and run
7473
`sudo jx npm run setupDesktop`.
7574

76-
Sudo is needed because this script installs a symbolic link into your global NPM directory.
75+
Sudo might be needed because this script installs a symbolic link into your global NPM directory.
7776

78-
You can run all the tests by going to Thali_CordovaPlugin/test/www/jxcore and issuing `jx UnitTest_app.js`. But the
79-
tests will happily run stand alone so you can run a test directly (e.g. `jx testConnectionTable.js`) thus allowing
80-
you to easily run and debug individual tests.
77+
You can run all the tests by going to Thali_CordovaPlugin/test/www/jxcore and issuing one of the following:
78+
79+
```
80+
$ jx npm test
81+
$ jx npm run test-meta
82+
$ jx npm run test-coordinated
83+
```
84+
85+
Some tests will also happily run stand alone so you can run a test directly (e.g. `jx bv_tests/testThaliCryptoManager.js`)
86+
thus allowing you to easily run and debug individual tests.
8187

8288
### Writing Unit Tests
8389
The Unit Tests are kept in Thali_CordovaPlugin/test/www/jxcore/bv_tests. So please put new tests there.

test/TestServer/TestFramework.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,14 @@ TestFramework.prototype.addDevice = function(device) {
9393
} else if (this.devices[device.platform].length >= this.requiredDevices[device.platform]) {
9494
// Discard surplus devices..
9595
logger.info("Discarding surplus device: %s", device.deviceName);
96+
this.removeDevice(device);
9697
device.socket.emit("discard");
9798
}
9899
}
99100

100-
TestFramework.prototype.removeDevice = function(device) {
101+
TestFramework.prototype.removeDevice = function (device) {
101102
var i = this.devices[device.platform].indexOf(device);
102103
this.devices[device.platform].splice(i, 1);
103-
assert(this.devices[device.platform].indexOf(device) == -1);
104-
}
104+
};
105105

106106
module.exports = TestFramework;

test/TestServer/UnitTestFramework.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ function UnitTestFramework(testConfig, _logger)
2222
var unitTestConfig = require(configFile);
2323

2424
UnitTestFramework.super_.call(this, testConfig, unitTestConfig, _logger);
25-
this.runningTests = [];
25+
26+
// Track which platforms we expect to be running on
27+
var self = this;
28+
self.runningTests = Object.keys(self.requiredDevices).filter(function (platform) {
29+
return self.requiredDevices[platform];
30+
});
2631
}
2732

2833
util.inherits(UnitTestFramework, TestFramework);
@@ -46,7 +51,7 @@ UnitTestFramework.prototype.startTests = function(platform, tests) {
4651
var self = this;
4752
function doTest(test, cb) {
4853

49-
logger.info("Running test: " + test);
54+
logger.info("Running on %s test: %s", platform, test);
5055

5156
// Perform a single test
5257

@@ -89,8 +94,17 @@ UnitTestFramework.prototype.startTests = function(platform, tests) {
8994
}
9095
});
9196

92-
// Start setup for this test
93-
device.socket.emit("setup", test);
97+
if (typeof jxcore !== 'undefined' && jxcore.utils.OSInfo().isMobile) {
98+
// The timeout is added as a workaround for an issue
99+
// where the client hasn't necessarily had time
100+
// to add correct listeners on the socket
101+
setTimeout(function() {
102+
// Start setup for this test
103+
device.socket.emit("setup", test);
104+
}, 1000);
105+
} else {
106+
device.socket.emit("setup", test);
107+
}
94108
});
95109
}
96110

@@ -106,7 +120,7 @@ UnitTestFramework.prototype.startTests = function(platform, tests) {
106120

107121
// ALL DONE !!
108122
// All devices have completed all their tests
109-
logger.info("Test run complete");
123+
logger.info("Test run on %s complete", platform);
110124

111125
// The whole point !! Log test results from the
112126
// server
@@ -117,7 +131,7 @@ UnitTestFramework.prototype.startTests = function(platform, tests) {
117131
device.socket.emit("complete");
118132
});
119133

120-
// We're done runnign for this platform..
134+
// We're done running for this platform..
121135
self.runningTests = self.runningTests.filter(function(p) {
122136
return (p != platform);
123137
});
@@ -130,7 +144,6 @@ UnitTestFramework.prototype.startTests = function(platform, tests) {
130144
}
131145

132146
toComplete = devices.length;
133-
this.runningTests.push(platform);
134147

135148
devices.forEach(function(device) {
136149
// Wait for devices to signal they've scheduled their

test/www/jxcore/PerfTest_app.js

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,30 +37,16 @@ function getDeviceCharacteristics(cb) {
3737
if (!myName || !bluetoothAddress) {
3838
console.log('An error while getting the device characteristics!');
3939
}
40-
testUtils.setMyName(myName);
40+
testUtils.setName(myName);
4141
cb(myName, bluetoothAddress);
42-
43-
// Below is only for logging purposes.
44-
// Once we have had the BT off and we just turned it on,
45-
// we need to wait untill the BLE support is reported rigth way
46-
// seen with LG G4, Not seen with Motorola Nexus 6.
47-
setTimeout(function () {
48-
Mobile('IsBLESupported').callNative(function (err) {
49-
if (err) {
50-
console.log('BLE is not supported: ' + err );
51-
return;
52-
}
53-
console.log("BLE is supported");
54-
});
55-
}, 5000);
5642
});
5743
});
5844
});
5945
} else {
6046
Mobile('GetDeviceName').callNative(function (deviceName) {
6147
// In case of iOS, the device name is used directly, because
6248
// the one returned in the one that user can set.
63-
testUtils.setMyName(deviceName);
49+
testUtils.setName(deviceName);
6450
cb(deviceName, null);
6551
});
6652
}

test/www/jxcore/UnitTest_app.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@
88

99
var testUtils = require("./lib/testUtils");
1010

11+
if (typeof Mobile === 'undefined') {
12+
global.Mobile = require('./lib/MobileUsingWifi.js');
13+
}
14+
1115
testUtils.toggleRadios(true);
1216

1317
Mobile('GetDeviceName').callNative(function (name) {
1418
console.log("My device name is: %s", name);
15-
testUtils.setMyName(name);
19+
testUtils.setName(name);
1620
require('./runTests.js');
1721
console.log('Test app app.js loaded');
1822
});

test/www/jxcore/bv_tests/testMultiplex.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ test('multiplex can send data', function (t) {
3333
socket.pipe(plex1).pipe(socket);
3434
});
3535

36-
server.listen(6001, function () {
37-
var socket = net.createConnection({port: 6001}, function () {
36+
server.listen(0, function () {
37+
var serverPort = server.address().port;
38+
var socket = net.createConnection({port: serverPort}, function () {
3839
var plex2 = multiplex();
3940
var stream = plex2.createStream();
4041
stream.write(new Buffer(testMessage));
@@ -48,12 +49,13 @@ test('muxServerBridge', function (t) {
4849
var len = 200;
4950
var testMessage = randomstring.generate(len);
5051
51-
var server = net.createServer(function (socket) {
52+
var testServer = net.createServer(function (socket) {
5253
socket.pipe(socket);
5354
});
5455
55-
server.listen(6001, function () {
56-
var muxServerBridge = tcpmultiplex.muxServerBridge(6001);
56+
testServer.listen(0, function () {
57+
var testServerPort = testServer.address().port;
58+
var muxServerBridge = tcpmultiplex.muxServerBridge(testServerPort);
5759
muxServerBridge.listen(function () {
5860
var serverPort = muxServerBridge.address().port;
5961

test/www/jxcore/bv_tests/testThaliCryptoManager.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ var path = require('path');
77
var crypto = require('crypto');
88
var tape = require('../lib/thali-tape');
99
var cryptomanager = require('thali/thalicryptomanager');
10-
var os = require('os');
10+
var testUtils = require('../lib/testUtils.js');
1111

1212
// get the values needed for running the tests
1313
var configValues = cryptomanager.getConfigValuesForTestingOnly();
1414

15-
var fileLocation = path.join(os.tmpdir(), './pkcs12folder');
15+
var fileLocation = path.join(testUtils.tmpDirectory(), './pkcs12folder');
1616

1717
// test setup & teardown activities
1818
var test = tape({

0 commit comments

Comments
 (0)