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

Plugins #865

Open
wants to merge 137 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
137 commits
Select commit Hold shift + click to select a range
9f8b98d
Added package.json for plugin_router.
mlucy Aug 11, 2016
98e828a
Added index.js to plugin_router.
mlucy Aug 12, 2016
8b3bcac
Added package.json for permissions plugin.
mlucy Aug 12, 2016
e1e13c6
checkpoint
mlucy Aug 12, 2016
f123d52
checkpoint
mlucy Aug 13, 2016
8cfac85
Reworked reliable stuff.
mlucy Aug 15, 2016
1378c09
added ReliableMetadata sketch
Aug 16, 2016
bd146d1
Added reliable shit.
mlucy Aug 16, 2016
2143e8c
style fixes
mlucy Aug 16, 2016
9dc76cf
merged
mlucy Aug 16, 2016
a35437d
style fixes
mlucy Aug 16, 2016
365896f
checkpoint
mlucy Aug 16, 2016
58cc7f3
fixed syntax
Aug 16, 2016
b10f02c
working on middleware execution
Aug 16, 2016
2651ec1
it build!
mlucy Aug 17, 2016
25b91b6
checkpoint
mlucy Aug 17, 2016
c9136c7
checkpoint
mlucy Aug 17, 2016
9425197
fixing test bugs
Aug 17, 2016
7fdb2f2
fixed more test problems
Aug 17, 2016
757fc07
fixed eslint problems
Aug 17, 2016
ea26fec
wrote broken graph code
mlucy Aug 18, 2016
1432a9e
fixed eslint errors in plugin router
Aug 18, 2016
7df9136
checkpoint
Aug 18, 2016
5748188
checkpoint
Aug 19, 2016
5094ea8
checkpoint
mlucy Aug 20, 2016
e4b93bc
fixed square brackets style
mlucy Aug 23, 2016
54ba00a
checkpoint
mlucy Aug 24, 2016
359039a
theoretically working
mlucy Aug 25, 2016
13d6109
moved logic from server to permissions plugin
Aug 25, 2016
75f96a9
moving horizon.js to index.js
Aug 25, 2016
9ef28ae
checkpoint
Aug 25, 2016
4bf76e8
camelcase changes
Aug 25, 2016
0c9f57a
checkpoint
Aug 25, 2016
b8d4a08
checkpoint
Aug 25, 2016
8a50370
cleanup of obsolete code
Aug 25, 2016
b370128
fixed server
Aug 25, 2016
82d20df
Everything works
Aug 25, 2016
c62e3e0
everything works a little more
Aug 26, 2016
386a8e3
getting stuff running
Aug 30, 2016
75cc00a
plugins almost working
Aug 31, 2016
bc7bdee
checkpoint
Aug 31, 2016
128aa95
checkpoint
Aug 31, 2016
77f3db8
working on stuff
mlucy Aug 31, 2016
7f7b975
collection broken
mlucy Sep 1, 2016
c99fd73
added stuff
mlucy Sep 1, 2016
102fdc0
fixing bugs in testing
Sep 1, 2016
b281558
reworking plugin dependencies
Sep 2, 2016
06c79d0
restructuring plugins module
Sep 2, 2016
7ce2cea
more plugins module resturcturing
Sep 2, 2016
032554a
more plugin reorganization
Sep 2, 2016
027d064
fixing eslint errors in plugins
Sep 2, 2016
26613f4
working on getting the test server running again
Sep 2, 2016
f948716
fixing es6 compat
Sep 2, 2016
12846c2
broke plugins up into separate modules
Sep 2, 2016
9cb6e71
reorganizing some plugin stuff
Sep 2, 2016
9cf5acd
added module for default plugins
Sep 2, 2016
dead3b0
working on getting dev environment easy to set up
Sep 2, 2016
7eab310
fixed up setupDev.sh to provision plugins
Sep 2, 2016
a78b0db
fixing bugs
Sep 2, 2016
1615b7a
fixed incorrect error handling in collection creation
Sep 2, 2016
43c921a
about to fix namespaces
mlucy Sep 3, 2016
f5a8415
fixed namespacing
mlucy Sep 3, 2016
a1dfb87
fixing bugs
Sep 5, 2016
16575ca
about to start moving and writing tests
Sep 5, 2016
0a26b50
stuffs
mlucy Sep 5, 2016
4a33c83
Merge branch 'next' into grey_plugins
Sep 5, 2016
2da2dc1
Merge branch 'plugins' into grey_plugins
Sep 5, 2016
7845099
migrated permissions template tests
Sep 5, 2016
ec572f1
adding source-map-support devDependency to plugins
Sep 5, 2016
3f42c9d
migrating server tests to integration tests
Sep 5, 2016
d6b196a
fix a few test bugs
Sep 7, 2016
9b1e023
added 5 sec wait for metadata to sync
Sep 7, 2016
b14fa0d
got protocol tests passing
Sep 8, 2016
03673ca
fixed collections and permissions readiness
Sep 8, 2016
890070f
fixed test create_collection
Sep 8, 2016
b4f7882
fixed some tests
Sep 8, 2016
750b95e
reworking plugin-router, added stubs for differend backend implementa…
Sep 8, 2016
02cfdb9
no longer pass server to plugins, but a curated plugin context
Sep 9, 2016
6fda005
got previously working tests working again
Sep 9, 2016
8079784
fixing problems in integration tests
Sep 9, 2016
9361715
fixed cleanup, removed old console log statements
Sep 9, 2016
06d1427
fixed some tests
Sep 9, 2016
0392e90
almost have all server tests running
Sep 10, 2016
f61425c
changed how user info is passed to validators
Sep 11, 2016
bddb240
fixed all server tests
Sep 11, 2016
dc9ef13
got test server running
Sep 11, 2016
328d124
checkpoint
Sep 13, 2016
da538ed
camelCasing and fixing tests
Sep 13, 2016
203b420
checkpoint
Sep 16, 2016
492ef1f
fixing build
Tryneus Oct 2, 2016
480da06
working on client for new protocol
Tryneus Oct 2, 2016
db8143d
checkpoint
Tryneus Oct 7, 2016
127e379
(maybe) working script for symlinking across modules in this repo
Tryneus Oct 7, 2016
7864924
fixing module symlinks and deps
Tryneus Oct 7, 2016
3ecc060
tests are running
Tryneus Oct 8, 2016
dfdae9f
server tests running
Tryneus Oct 8, 2016
7f215bd
:checkpoint
Tryneus Oct 12, 2016
0de9487
checkpoint
Tryneus Oct 13, 2016
fe2c89a
checkpoint
Tryneus Oct 15, 2016
8e8b363
lots of refactoring and style fixes
Tryneus Oct 18, 2016
85e7643
tests passing again
Tryneus Oct 20, 2016
a3c6e4d
camelcasing
Tryneus Oct 20, 2016
2430c8a
fixed some problems in client tests
Tryneus Oct 23, 2016
1c2340c
working on client socket handling
Tryneus Oct 26, 2016
b565a41
checkpoint
Tryneus Oct 27, 2016
b5d4da7
checkpoint
Tryneus Oct 27, 2016
68e7a07
fixed client reconnection logic
Tryneus Oct 27, 2016
3913388
some client tests working
Tryneus Oct 27, 2016
a8b4054
fixing tests, sort of
Tryneus Oct 28, 2016
72b1839
compatibility changes and test fixes
Tryneus Oct 29, 2016
01f0a29
checkpoint
Tryneus Dec 12, 2016
8307bcb
add server auth unit tests
Tryneus Dec 18, 2016
c303677
moving client to client_connection
Tryneus Dec 19, 2016
05d1499
add tests, fix lint errors
Tryneus Dec 19, 2016
dca7a64
add response tests
Tryneus Dec 19, 2016
e995e4b
fix flipped logic in findAll
Tryneus Dec 20, 2016
63ec280
fix find query
Tryneus Dec 20, 2016
5ffde58
fix some client tests and compatibility
Tryneus Dec 21, 2016
a63596e
fixing bugs
Tryneus Dec 23, 2016
ae85fcf
fixing tests
Tryneus Dec 23, 2016
ca16d29
fixing tests and style
Tryneus Dec 24, 2016
baeac8f
fixing tests
Tryneus Dec 24, 2016
1ddd5cf
fixing tests
Tryneus Dec 24, 2016
c3a015b
fix some tests, currentUser
Tryneus Dec 25, 2016
bdc2be5
fix some tests
Tryneus Dec 25, 2016
83d6008
fix between problems
Tryneus Dec 25, 2016
a0cce9c
all client tests passing
Tryneus Dec 25, 2016
14aa2c9
removing old dependency
Tryneus Dec 26, 2016
d5e82b4
style and cleanup
Tryneus Dec 27, 2016
a8c1564
fix some problems in examples
Tryneus Dec 28, 2016
74bc243
some router fixes
Tryneus Dec 28, 2016
aa4b826
fix some problems in the framework integrations
Tryneus Dec 29, 2016
336b5ea
change versions
Tryneus Jan 28, 2017
6e3ce54
trying to fix setupDev.sh
Tryneus Jan 29, 2017
a39c252
temporarily sequester some test code
Tryneus Jan 29, 2017
4eb7ff0
trying to fix dev setup
Tryneus Jan 29, 2017
d7e8223
more missing links
Tryneus Jan 30, 2017
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
Prev Previous commit
Next Next commit
fixing problems in integration tests
  • Loading branch information
Marc Hesse committed Sep 9, 2016
commit 8079784c007ac79a0febcf0649a65158afc8d2fb
5 changes: 5 additions & 0 deletions cli/src/utils/start_rdb_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,22 @@ class RethinkdbServer {
}

close() {
console.log('closing rdb server');
return new Promise((resolve) => {
if (this.proc.exitCode !== null) {
console.log('rdb server already exited');
resolve();
} else {
console.log('killing server with sigterm');
this.proc.kill('SIGTERM');

this.proc.once('exit', () => {
console.log('rdb server exited');
resolve();
});

setTimeout(() => {
console.log('killing server with sigkill');
this.proc.kill('SIGKILL');
resolve();
}, 20000).unref();
Expand Down
6 changes: 5 additions & 1 deletion plugin-router/base/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class PluginRouter extends EventEmitter {
}

close() {
console.log(`closing plugin-router: ${JSON.stringify(this.plugins.keys())}`);
return Promise.all(Array.from(this.plugins.keys()).map((p) => this.remove(p)));
}

Expand Down Expand Up @@ -71,14 +72,17 @@ class PluginRouter extends EventEmitter {
}

this.plugins.delete(name);
console.log(`deactivating plugin ${name}`);
return plugin.activatePromise.then((active) => {
for (const m in active.methods) {
this.horizon.removeMethod(m);
}
if (plugin.deactivate) {
return plugin.deactivate(this.context, plugin.options,
reason || 'Removed from PluginRouter.');
reason || 'Removed from PluginRouter.').then(() =>
console.log(`plugin ${name} deactivated, removing methods`));
}
console.log(`plugin ${name} has no deactivate, done`);
});
}

Expand Down
3 changes: 0 additions & 3 deletions plugin-utils/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,11 @@ const reqlOptions = {
binaryFormat: 'raw',
};

const versionField = '$hz_v$';

module.exports = {
rethinkdbVersionCheck,
remakeError,
isObject,
reqlOptions,
versionField,
reads: require('./reads'),
writes: require('./writes'),
test: require('./test'),
Expand Down
7 changes: 3 additions & 4 deletions plugin-utils/src/writes.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
'use strict';

const utils = require('./utils');

const assert = require('assert');

const {r} = require('@horizon/server');

const hz_v = utils.version_field;
const hz_v = '$hz_v$';

// Common functionality used by write requests
const invalidated_msg = 'Write invalidated by another request, try again.';
Expand All @@ -15,7 +13,7 @@ const timeout_msg = 'Operation timed out.';
const unauthorized_msg = 'Operation not permitted.';

function apply_version(row, new_version) {
row.merge(r.object(hz_v, new_version));
return row.merge(r.object(hz_v, new_version));
}

function make_write_response(data) {
Expand Down Expand Up @@ -189,4 +187,5 @@ module.exports = {
retry_loop,
validate_old_row_required,
validate_old_row_optional,
versionField: hz_v,
};
7 changes: 5 additions & 2 deletions plugins/collection/src/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,11 @@ module.exports = {
});
},
deactivate: (context, options) => {
if (context[options.name]) {
context[options.name].close();
console.log('deactivating collections plugin');
const metadata = context[options.name];
delete context[options.name];
if (metadata) {
metadata.close();
}
},
};
Expand Down
3 changes: 2 additions & 1 deletion plugins/remove/src/remove.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';

const {r} = require('@horizon/server');
const {reqlOptions, writes, versionField: hz_v} = require('@horizon/plugin-utils');
const {reqlOptions, writes} = require('@horizon/plugin-utils');
const hz_v = writes.versionField;

function remove(context) {
return (request, response, next) => {
Expand Down
3 changes: 2 additions & 1 deletion plugins/replace/src/replace.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';

const {r} = require('@horizon/server');
const {reqlOptions, writes, versionField: hz_v} = require('@horizon/plugin-utils');
const {reqlOptions, writes} = require('@horizon/plugin-utils');
const hz_v = writes.versionField;

function replace(context) {
return (request, response, next) => {
Expand Down
3 changes: 2 additions & 1 deletion plugins/store/src/store.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';

const {r} = require('@horizon/server');
const {reqlOptions, writes, versionField: hz_v} = require('@horizon/plugin-utils');
const {reqlOptions, writes} = require('@horizon/plugin-utils');
const hz_v = writes.versionField;

function store(context) {
return (request, response, next) => {
Expand Down
3 changes: 2 additions & 1 deletion plugins/update/src/update.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';

const {r} = require('@horizon/server');
const {reqlOptions, writes, versionField: hz_v} = require('@horizon/plugin-utils');
const {reqlOptions, writes} = require('@horizon/plugin-utils');
const hz_v = writes.versionField;

function update(context) {
return (request, response, next) => {
Expand Down
3 changes: 2 additions & 1 deletion plugins/upsert/src/upsert.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';

const {r} = require('@horizon/server');
const {reqlOptions, writes, versionField: hz_v} = require('@horizon/plugin-utils');
const {reqlOptions, writes} = require('@horizon/plugin-utils');
const hz_v = writes.versionField;

function upsert(context) {
return (request, response, next) => {
Expand Down
21 changes: 9 additions & 12 deletions test/src/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ const all_suites = ['prereq',
'watch',
'write',
'permissions'];

const collection = 'test';

before('Start RethinkDB Server', () => utils.start_rethinkdb());
after('Stop RethinkDB Server', () => utils.stop_rethinkdb());
before('Start servers', () => utils.startServers());
after('Stop servers', () => utils.stopServers());

before(`Creating general-purpose collection: '${collection}'`,
() => utils.create_collection(collection));

beforeEach(
/** @this mocha */
Expand All @@ -25,14 +29,7 @@ afterEach(
/** @this mocha */
function() { logger.info(`End test '${this.currentTest.title}'`); });

describe('Horizon Server', () => {
before('Start Horizon Server', utils.start_horizon_server);
after('Close Horizon Server', utils.close_horizon_server);

before(`Creating general-purpose collection: '${collection}'`,
() => utils.create_collection(collection));
beforeEach('Connect Horizon Client', utils.open_horizon_conn);
afterEach('Close Horizon Client', utils.close_horizon_conn);

beforeEach('Connect Horizon Client', utils.open_horizon_conn);
afterEach('Close Horizon Client', utils.close_horizon_conn);
all_suites.forEach((s) => require(`./${s}`).suite(collection));
});
all_suites.forEach((s) => require(`./${s}`).suite(collection));
131 changes: 69 additions & 62 deletions test/src/test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,26 @@ const r = require('rethinkdb');
const websocket = require('ws');

const project_name = 'integration_test';
const data_dir = './rethinkdb_data_test';
const dataDir = './rethinkdb_data_test';

const log_file = `./horizon_test_${process.pid}.log`;
logger.level = 'debug';
logger.add(logger.transports.File, {filename: log_file});
logger.remove(logger.transports.Console);

// Variables used by most tests
let rdb_server, rdb_http_port, rdb_port, rdb_conn, horizon_server, horizon_port, horizon_conn, horizon_listeners, plugin_router;
let rdb_server, rdb_http_port, rdb_port, rdb_conn, horizon_server, horizon_port, horizon_conn, horizon_listeners, plugin_router, http_server;
let horizon_authenticated = false;

const start_rethinkdb = () => {
logger.info('removing dir');
rm_sync_recursive(data_dir);
function startServers() {
assert.strictEqual(horizon_server, undefined);
assert.strictEqual(plugin_router, undefined);

logger.info(`removing old rethinkdb data directory: ${dataDir}`);
rm_sync_recursive(dataDir);

logger.info('creating server');
return start_rdb_server({dataDir: data_dir}).then((server) => {
return start_rdb_server({dataDir}).then((server) => {
rdb_server = server;
rdb_port = server.driver_port;
rdb_http_port = server.http_port;
Expand All @@ -41,13 +44,66 @@ const start_rethinkdb = () => {
}).then((conn) => {
logger.info('connected');
rdb_conn = conn;
return r.dbCreate(project_name).run(conn);
}).then((res) => {
assert.strictEqual(res.dbs_created, 1);
}).then(() => {
logger.info('creating http server');

http_server = new http.Server();
return new Promise((resolve, reject) => {
http_server.listen(0, () => {
logger.info('creating horizon server');
horizon_port = http_server.address().port;
horizon_server = new horizon.Server(http_server, {
project_name,
rdb_port,
auth: {
token_secret: 'hunter2',
allow_unauthenticated: true,
},
});

plugin_router = new PluginRouter(horizon_server);
const plugins_promise = plugin_router.add(defaults, {
auto_create_collection: true,
auto_create_index: true,
});

horizon_server.events.on('ready', () => {
logger.info('horizon server ready');
plugins_promise.then(resolve).catch(reject);
});
horizon_server.events.on('unready', (server, err) => {
logger.info(`horizon server unready: ${err}`);
});
});
http_server.on('error', reject);
});
});
};
}

function stopServers() {
let localRdbServer = rdb_server;
let localPluginRouter = plugin_router;
let localHorizonServer = horizon_server;
plugin_router = undefined;
horizon_server = undefined;
rdb_server = undefined;

const stop_rethinkdb = () => rdb_server && rdb_server.close();
return Promise.resolve().then(() => {
if (localPluginRouter) {
return localPluginRouter.close();
}
}).then(() => {
if (localHorizonServer) {
localHorizonServer.events.removeAllListeners('ready');
localHorizonServer.events.removeAllListeners('unready');
return localHorizonServer.close();
}
}).then(() => {
if (localRdbServer) {
localRdbServer.close();
}
});
}

// Used to prefix reql queries with the underlying table of a given collection
const table = (collection) =>
Expand Down Expand Up @@ -125,55 +181,6 @@ const populate_collection = (collection, rows) => {
}
};

const start_horizon_server = (done) => {
logger.info('creating http server');
assert.strictEqual(horizon_server, undefined);
assert.strictEqual(plugin_router, undefined);

const http_server = new http.Server();
http_server.listen(0, () => {
logger.info('creating horizon server');
horizon_port = http_server.address().port;
horizon_server = new horizon.Server(http_server, {
project_name,
rdb_port,
auth: {
token_secret: 'hunter2',
allow_unauthenticated: true,
},
});

plugin_router = new PluginRouter(horizon_server);
const plugins_promise = plugin_router.add(defaults, {
auto_create_collection: true,
auto_create_index: true,
});

horizon_server.events.on('ready', () => {
logger.info('horizon server ready');
plugins_promise.then(() => done()).catch(done);
});
horizon_server.events.on('unready', (server, err) => {
logger.info(`horizon server unready: ${err}`);
});
});
http_server.on('error', (err) => done(err));
};

const close_horizon_server = () => {
if (plugin_router !== undefined) {
plugin_router.close();
}
plugin_router = undefined;

if (horizon_server !== undefined) {
horizon_server.events.removeAllListeners('ready');
horizon_server.events.removeAllListeners('unready');
horizon_server.close();
}
horizon_server = undefined;
};

const add_horizon_listener = (request_id, cb) => {
assert(horizon_authenticated, 'horizon_conn was not authenticated before making requests');
assert.notStrictEqual(request_id, undefined);
Expand Down Expand Up @@ -306,12 +313,12 @@ module.exports = {
horizon_port: () => horizon_port,
horizon_listeners: () => horizon_listeners,

start_rethinkdb, stop_rethinkdb,
startServers, stopServers,

create_collection,
populate_collection,
clear_collection,

start_horizon_server, close_horizon_server,
open_horizon_conn, close_horizon_conn,
horizon_auth, horizon_admin_auth, horizon_default_auth,
add_horizon_listener, remove_horizon_listener,
Expand Down
6 changes: 3 additions & 3 deletions test/src/test/write.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const pluginUtils = require('@horizon/plugin-utils');
const assert = require('assert');
const crypto = require('crypto');

const hz_v = pluginUtils.version_field;
const hz_v = pluginUtils.writes.versionField;
const invalidated_msg = pluginUtils.writes.invalidated_msg;

// Before each test, ids [0, 4) will be present in the collection
Expand Down Expand Up @@ -48,7 +48,7 @@ const all_tests = (collection) => {

const make_request = (type, data, options) => ({
request_id: crypto.randomBytes(4).readUInt32BE(),
options: Object.assign({type: []}, options || {}, {collection, data}),
options: Object.assign({}, options || {}, {collection: [collection], [type]: data}),
});

const check_collection = (expected, done) => {
Expand Down Expand Up @@ -571,7 +571,7 @@ const all_tests = (collection) => {
// per iteration with the database. In order to test timeouts, we use a
// timeout of zero, so the other rows should immediately error.
describe('Zero Timeout', () => {
const timeout = {timeout: 0};
const timeout = {timeout: [0]};
const test_data = [{id: 0, value: 0}];
beforeEach('Populate collection', () => utils.populate_collection(collection, test_data));

Expand Down