Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add retry in templates to wait realtime notifications #161

Merged
merged 45 commits into from
Nov 30, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
a677a3d
[realtime tests] add sleep to wait notifications
Aschen Nov 23, 2018
0b0a6cf
[realtime tests] extract sleep from the code snippets
Aschen Nov 23, 2018
21bf4a7
[realtime tests] remove sleep in cpp snippet
Aschen Nov 23, 2018
e32e360
[realtime tests] increase sleep for js
Aschen Nov 23, 2018
91857f3
[realtime tests] use retry in cpp template
Aschen Nov 23, 2018
4cdc08a
[realtime tests] use retry in java template
Aschen Nov 23, 2018
24a87c5
[realtime tests] use retry in go template
Aschen Nov 23, 2018
46b7010
[realtime tests] use retry in js template
Aschen Nov 23, 2018
720997d
[realtime tests] nitpicking
Aschen Nov 23, 2018
706ea6c
[realtime tests] prevent infinite loops
Aschen Nov 23, 2018
cb9253a
[realtime tests] exit with non-zero code when timeout in go
Aschen Nov 23, 2018
9639cd2
[realtime tests] add sleep to wait notifications
Aschen Nov 23, 2018
35b338d
[realtime tests] extract sleep from the code snippets
Aschen Nov 23, 2018
1199b28
[realtime tests] remove sleep in cpp snippet
Aschen Nov 23, 2018
6ca00a9
[realtime tests] increase sleep for js
Aschen Nov 23, 2018
a555b16
[realtime tests] use retry in cpp template
Aschen Nov 23, 2018
89700bf
[realtime tests] use retry in java template
Aschen Nov 23, 2018
948490f
[realtime tests] use retry in go template
Aschen Nov 23, 2018
37efd20
[realtime tests] use retry in js template
Aschen Nov 23, 2018
007bed9
[realtime tests] nitpicking
Aschen Nov 23, 2018
41d634c
[realtime tests] prevent infinite loops
Aschen Nov 23, 2018
7cd127d
[realtime tests] exit with non-zero code when timeout in go
Aschen Nov 23, 2018
8ea341f
Merge branch 'fix-realtime-tests' of github.com:kuzzleio/documentatio…
Aschen Nov 27, 2018
4b5e07e
[realtime tests] fix js realtime
Aschen Nov 27, 2018
c9ebf6d
[realtime tests] fix js realtime
Aschen Nov 27, 2018
851e07f
[c++] update templates to the latest SDK version
scottinet Nov 28, 2018
c875266
[templates] C++: kuzzle->connect now throws
scottinet Nov 28, 2018
0d19c20
[cleanup] revert type change
scottinet Nov 28, 2018
e944bba
[c++] upgrade SDK install to the latest changes
scottinet Nov 28, 2018
2a8dcf9
Merge remote-tracking branch 'origin/upgrade-cpp-templates' into fix-…
scottinet Nov 28, 2018
c181328
Merge remote-tracking branch 'origin/master' into fix-realtime-tests
scottinet Nov 28, 2018
f6489d2
[c++] upgrade code snippets
scottinet Nov 28, 2018
154cce2
[java] upgrade templates to the new kuzzle constructor
scottinet Nov 28, 2018
6559596
Merge remote-tracking branch 'origin/upgrade-cpp-templates' into fix-…
scottinet Nov 28, 2018
94bbb9c
[realtime] upgrade templates to the latest kuzzle constructor
scottinet Nov 28, 2018
5a67369
[realtime] wait for 30s before throwing a timeout
scottinet Nov 28, 2018
9e64df3
[templates] realtime: timeout after 30s
scottinet Nov 29, 2018
de6e9d3
[realtime] JS template: exit even if the event loop is not empty
scottinet Nov 29, 2018
ea3e090
[realtime] JS: stricter tests + fix explanation
scottinet Nov 29, 2018
f20db37
[snippets] multi-snippets wrongly check column precedence
scottinet Nov 29, 2018
7645862
[realtime] stricter tests + snippet fixes
scottinet Nov 29, 2018
f8f8e20
[realtime] stabilize realtime tests
scottinet Nov 29, 2018
ee3b481
[templates] C++: getPort() is now only accessible through the Protoco…
scottinet Nov 30, 2018
3b3306c
Merge remote-tracking branch 'origin/master' into fix-realtime-tests
scottinet Nov 30, 2018
ee6d075
[java] fix user notifications snippet
scottinet Nov 30, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,28 +1,13 @@
function callback (notification) {
if (notification.type === 'user') {
console.log(notification);
console.log(notification.volatile);
/*
{ status: 200,
timestamp: 1539696822690,
Aschen marked this conversation as resolved.
Show resolved Hide resolved
volatile: { sdkVersion: '6.0.0-beta-2', username: 'nina vkote' },
index: 'nyc-open-data',
collection: 'yellow-taxi',
controller: 'realtime',
action: 'subscribe',
protocol: 'websocket',
user: 'in',
result: { count: 2 },
type: 'user',
room: '14b675feccf5ac320456ef0dbdf6c1fa-0bab84b784bbf372' }
{ sdkVersion: '<current SDK version>', username: 'nina vkote' },
*/
console.log(`Currently ${notification.result.count} users in the room`);
}
}

// instantiate a second kuzzle client because
// the same sdk instance does not receive his own notifications
const fuzzle = new Kuzzle('websocket', { host: 'kuzzle' });

try {
const filters = { exists: 'name' };
// Subscribe users notifications
Expand All @@ -36,19 +21,21 @@ try {
options
);

// instantiate a second kuzzle client because
// subscribing again to the same filters won't be considered
// by Kuzzle as new users
const kuzzle2 = new Kuzzle('websocket', { host: 'kuzzle' });
await kuzzle2.connect();

// Subscribe to the same room with the second client
const opfions = { users: 'all', volatile: { username: 'nina vkote' } };
await fuzzle.connect();
await fuzzle.realtime.subscribe(
const options2 = { users: 'all', volatile: { username: 'nina vkote' } };
await kuzzle2.realtime.subscribe(
'nyc-open-data',
'yellow-taxi',
filters,
() => {},
opfions
options2
);

await kuzzle.realtime.unsubscribe(roomId);
fuzzle.disconnect();
} catch (error) {
console.log(error.message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ hooks:
before: curl -X POST kuzzle:7512/nyc-open-data/_create ; curl -X PUT kuzzle:7512/nyc-open-data/yellow-taxi/
after:
template: realtime
expected: Currently 2 users in the room
expected:
- "username: 'nina vkote'"
- "Currently 2 users in the room"
15 changes: 9 additions & 6 deletions test/lib/runners/baseRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ module.exports = class BaseRunner {
previous = null;

for (const e of expected) {
let match = null;
let
match = null,
index;

for (let i = 0; i < stdout.length && match === null; i++) {
match = stdout[i].match(e);
for (index = 0; index < stdout.length && match === null; index++) {
match = stdout[index].match(e);
}

if (match === null) {
Expand All @@ -76,14 +78,15 @@ module.exports = class BaseRunner {
}));
}

if (match.index < lastIndex) {
if (index < lastIndex) {
return reject(new TestResult({
code: 'ERR_ORDER',
actualOrder: [previous, e]
actualOrder: [previous, e],
actual: stdout
}));
}

lastIndex = match.index;
lastIndex = index;
previous = e;
}

Expand Down
3 changes: 2 additions & 1 deletion test/templates/realtime.tpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function sleep (ms) {
console.log = consoleLog;
console.log(...outputs);

kuzzle.disconnect();
// force exit: do not wait for the event loop to be empty
process.exit(0);
}
})();