@na1647/offshore-adapter-tests 0.0.0-stage → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +1 -0
- package/.eslintrc +35 -0
- package/.travis.yml +32 -0
- package/CHANGELOG.md +24 -0
- package/Dockerfile +7 -0
- package/LICENSE.md +11 -0
- package/README.md +71 -2
- package/docker-compose.yml +32 -0
- package/features/autoIncrement/README.md +37 -0
- package/features/autoIncrement/core/autoIncrement.test.js +151 -0
- package/features/autoIncrement/sequential/autoIncrementSequential.test.js +104 -0
- package/features/autoIncrement/support/autoInc.fixture.js +25 -0
- package/features/compositePrimaryKey/core/compositePrimaryKey.test.js +67 -0
- package/features/compositePrimaryKey/support/fixture.js +24 -0
- package/features/compositeUnique/core/compositeUnique.test.js +67 -0
- package/features/compositeUnique/support/fixture.js +30 -0
- package/features/crossAdapter/core/crossAdapter.js +119 -0
- package/features/crossAdapter/support/bootstrap.js +106 -0
- package/features/sequences/core/sequences.test.js +110 -0
- package/features/sequences/support/mariadb.js +23 -0
- package/features/sequences/support/oracle.js +23 -0
- package/features/sequences/support/postgres.js +23 -0
- package/features/spatial/core/geojson.test.js +68 -0
- package/features/spatial/support/fixtures.js +82 -0
- package/features/spatial/support/models.js +45 -0
- package/features/unique/README.md +18 -0
- package/features/unique/core/unique.test.js +107 -0
- package/features/unique/support/unique.fixture.js +26 -0
- package/interfaces/associations/belongsTo/create.js +41 -0
- package/interfaces/associations/belongsTo/create.nested.customPK.js +61 -0
- package/interfaces/associations/belongsTo/create.nested.js +52 -0
- package/interfaces/associations/belongsTo/dynamicFinder.js +213 -0
- package/interfaces/associations/belongsTo/find.populate.js +145 -0
- package/interfaces/associations/belongsTo/findOne.populate.js +84 -0
- package/interfaces/associations/belongsTo/modifiers.js +275 -0
- package/interfaces/associations/belongsTo/multipleForeignKeys.js +70 -0
- package/interfaces/associations/belongsTo/update.nested.customPK.js +141 -0
- package/interfaces/associations/belongsTo/update.nested.js +174 -0
- package/interfaces/associations/deep.associations.test.js +437 -0
- package/interfaces/associations/find.associations.test.js +92 -0
- package/interfaces/associations/hasMany/add.js +106 -0
- package/interfaces/associations/hasMany/create.nested.customPK.js +113 -0
- package/interfaces/associations/hasMany/create.nested.js +96 -0
- package/interfaces/associations/hasMany/find.populate.customPK.js +75 -0
- package/interfaces/associations/hasMany/find.populate.js +219 -0
- package/interfaces/associations/hasMany/find.populate.where.js +148 -0
- package/interfaces/associations/hasMany/findOne.populate.js +88 -0
- package/interfaces/associations/hasMany/modifiers.js +560 -0
- package/interfaces/associations/hasMany/multipleForeignKeys.js +113 -0
- package/interfaces/associations/hasMany/remove.js +96 -0
- package/interfaces/associations/hasMany/update.nested.customPK.js +148 -0
- package/interfaces/associations/hasMany/update.nested.js +202 -0
- package/interfaces/associations/manyToMany/add.js +136 -0
- package/interfaces/associations/manyToMany/create.nested.customPK.js +109 -0
- package/interfaces/associations/manyToMany/create.nested.js +96 -0
- package/interfaces/associations/manyToMany/destroy.js +128 -0
- package/interfaces/associations/manyToMany/find.populate.js +109 -0
- package/interfaces/associations/manyToMany/find.populate.where.js +75 -0
- package/interfaces/associations/manyToMany/find.populate.withSchema.js +91 -0
- package/interfaces/associations/manyToMany/findOne.populate.js +86 -0
- package/interfaces/associations/manyToMany/modifiers.js +558 -0
- package/interfaces/associations/manyToMany/remove.js +103 -0
- package/interfaces/associations/manyToMany/update.js +105 -0
- package/interfaces/associations/manyToMany/update.nested.customPK.js +315 -0
- package/interfaces/associations/manyToMany/update.nested.js +355 -0
- package/interfaces/associations/manyToManyThrough/add.js +109 -0
- package/interfaces/associations/manyToManyThrough/create.nested.customPK.js +118 -0
- package/interfaces/associations/manyToManyThrough/create.nested.js +114 -0
- package/interfaces/associations/manyToManyThrough/find.populate.customPK.js +76 -0
- package/interfaces/associations/manyToManyThrough/find.populate.js +120 -0
- package/interfaces/associations/manyToManyThrough/find.populate.where.js +157 -0
- package/interfaces/associations/manyToManyThrough/findOne.populate.js +93 -0
- package/interfaces/associations/manyToManyThrough/modifiers.js +560 -0
- package/interfaces/associations/manyToManyThrough/multipleForeignKeys.js +118 -0
- package/interfaces/associations/manyToManyThrough/remove.js +98 -0
- package/interfaces/associations/manyToManyThrough/update.nested.customPK.js +150 -0
- package/interfaces/associations/manyToManyThrough/update.nested.js +202 -0
- package/interfaces/associations/oneToOne/create.js +41 -0
- package/interfaces/associations/oneToOne/create.nested.customPK.js +61 -0
- package/interfaces/associations/oneToOne/create.nested.js +52 -0
- package/interfaces/associations/oneToOne/dynamicFinder.js +68 -0
- package/interfaces/associations/oneToOne/find.populate.js +127 -0
- package/interfaces/associations/oneToOne/findOne.populate.js +83 -0
- package/interfaces/associations/oneToOne/modifiers.js +275 -0
- package/interfaces/associations/oneToOne/multipleForeignKeys.js +69 -0
- package/interfaces/associations/oneToOne/update.nested.customPK.js +141 -0
- package/interfaces/associations/oneToOne/update.nested.js +174 -0
- package/interfaces/associations/support/bootstrap.js +82 -0
- package/interfaces/associations/support/fixtures/belongsTo.child.customPK.fixture.js +25 -0
- package/interfaces/associations/support/fixtures/belongsTo.child.fixture.js +25 -0
- package/interfaces/associations/support/fixtures/belongsTo.parent.customPK.fixture.js +26 -0
- package/interfaces/associations/support/fixtures/belongsTo.parent.fixture.js +28 -0
- package/interfaces/associations/support/fixtures/crud.fixture.js +53 -0
- package/interfaces/associations/support/fixtures/deep.address.fixture.js +21 -0
- package/interfaces/associations/support/fixtures/deep.breakdown.fixture.js +23 -0
- package/interfaces/associations/support/fixtures/deep.company.fixture.js +29 -0
- package/interfaces/associations/support/fixtures/deep.country.fixture.js +25 -0
- package/interfaces/associations/support/fixtures/deep.departement.fixture.js +24 -0
- package/interfaces/associations/support/fixtures/deep.driver.fixture.js +32 -0
- package/interfaces/associations/support/fixtures/deep.ride.fixture.js +23 -0
- package/interfaces/associations/support/fixtures/deep.seller.fixture.js +33 -0
- package/interfaces/associations/support/fixtures/deep.taxi.fixture.js +36 -0
- package/interfaces/associations/support/fixtures/hasMany.child.fixture.js +33 -0
- package/interfaces/associations/support/fixtures/hasMany.customPK.fixture.js +22 -0
- package/interfaces/associations/support/fixtures/hasMany.parent.fixture.js +28 -0
- package/interfaces/associations/support/fixtures/hasManyThrough.child.customPK.fixture.js +32 -0
- package/interfaces/associations/support/fixtures/hasManyThrough.parent.customPK.fixture.js +23 -0
- package/interfaces/associations/support/fixtures/hasManyThrough.stadium.fixture.js +20 -0
- package/interfaces/associations/support/fixtures/hasManyThrough.team.fixture.js +35 -0
- package/interfaces/associations/support/fixtures/hasManyThrough.through.customPK.fixture.js +18 -0
- package/interfaces/associations/support/fixtures/hasManyThrough.venue.fixture.js +18 -0
- package/interfaces/associations/support/fixtures/manyToMany.driver.customPK.fixture.js +22 -0
- package/interfaces/associations/support/fixtures/manyToMany.driver.fixture.js +25 -0
- package/interfaces/associations/support/fixtures/manyToMany.driver.withSchema.fixture.js +25 -0
- package/interfaces/associations/support/fixtures/manyToMany.taxi.customPK.fixture.js +21 -0
- package/interfaces/associations/support/fixtures/manyToMany.taxi.fixture.js +30 -0
- package/interfaces/associations/support/fixtures/manyToMany.taxi.withSchema.fixture.js +24 -0
- package/interfaces/associations/support/fixtures/multipleAssociations.fixture.js +54 -0
- package/interfaces/associations/support/fixtures/multipleOneToOneAssociations.fixture.js +40 -0
- package/interfaces/associations/support/fixtures/multipleThroughAssociations.fixture.js +79 -0
- package/interfaces/associations/support/fixtures/oneToOne.customPK.fixture.js +47 -0
- package/interfaces/associations/support/fixtures/oneToOne.fixture.js +52 -0
- package/interfaces/associations/support/fixtures.js +41 -0
- package/interfaces/datastore/datastore.test.js +63 -0
- package/interfaces/migratable/definition.test.js +65 -0
- package/interfaces/migratable/migrate.alter.test.js +55 -0
- package/interfaces/migratable/migrate.create.test.js +120 -0
- package/interfaces/migratable/migrate.drop.test.js +47 -0
- package/interfaces/migratable/migrate.safe.test.js +25 -0
- package/interfaces/migratable/schema.test.js +117 -0
- package/interfaces/migratable/support/bootstrap.js +55 -0
- package/interfaces/migratable/support/bootstrapFn.js +54 -0
- package/interfaces/migratable/support/fixtures/alter.fixture.js +12 -0
- package/interfaces/migratable/support/fixtures/create.fixture.js +12 -0
- package/interfaces/migratable/support/fixtures/crud.fixture.js +53 -0
- package/interfaces/migratable/support/fixtures/custom.fixture.js +17 -0
- package/interfaces/migratable/support/fixtures/drop.fixture.js +12 -0
- package/interfaces/migratable/support/fixtures/safe.fixture.js +12 -0
- package/interfaces/migratable/support/fixtures/schema.fixture.js +23 -0
- package/interfaces/queryable/caseInsensitive.test.js +196 -0
- package/interfaces/queryable/count.test.js +51 -0
- package/interfaces/queryable/dynamicFinders.test.js +179 -0
- package/interfaces/queryable/findLike.test.js +34 -0
- package/interfaces/queryable/findOneLike.test.js +28 -0
- package/interfaces/queryable/modifiers/average.modifier.test.js +55 -0
- package/interfaces/queryable/modifiers/contains.modifier.test.js +82 -0
- package/interfaces/queryable/modifiers/endsWith.modifier.test.js +82 -0
- package/interfaces/queryable/modifiers/greaterThan.modifier.test.js +335 -0
- package/interfaces/queryable/modifiers/groupBy.modifier.test.js +123 -0
- package/interfaces/queryable/modifiers/in.modifier.test.js +76 -0
- package/interfaces/queryable/modifiers/lessThan.modifier.test.js +223 -0
- package/interfaces/queryable/modifiers/like.modifier.test.js +50 -0
- package/interfaces/queryable/modifiers/limit.modifier.test.js +60 -0
- package/interfaces/queryable/modifiers/max.modifier.test.js +68 -0
- package/interfaces/queryable/modifiers/min.modifier.test.js +68 -0
- package/interfaces/queryable/modifiers/not.modifier.test.js +80 -0
- package/interfaces/queryable/modifiers/notIn.modifier.test.js +69 -0
- package/interfaces/queryable/modifiers/or.modifier.test.js +142 -0
- package/interfaces/queryable/modifiers/select.modifier.test.js +118 -0
- package/interfaces/queryable/modifiers/skip.modifier.test.js +59 -0
- package/interfaces/queryable/modifiers/sort.modifier.test.js +160 -0
- package/interfaces/queryable/modifiers/startsWith.modifier.test.js +83 -0
- package/interfaces/queryable/modifiers/sum.modifier.test.js +68 -0
- package/interfaces/queryable/support/bootstrap.js +80 -0
- package/interfaces/queryable/support/fixtures/crud.fixture.js +54 -0
- package/interfaces/scalable/README.md +19 -0
- package/interfaces/scalable/crud.test.js +73 -0
- package/interfaces/scalable/queries.test.js +9 -0
- package/interfaces/scalable/support/crud.fixture.js +60 -0
- package/interfaces/semantic/create.test.js +110 -0
- package/interfaces/semantic/createEach.test.js +50 -0
- package/interfaces/semantic/destroy.js +147 -0
- package/interfaces/semantic/find.test.js +91 -0
- package/interfaces/semantic/findOne.test.js +60 -0
- package/interfaces/semantic/findOrCreate.test.js +91 -0
- package/interfaces/semantic/findOrCreateEach.test.js +75 -0
- package/interfaces/semantic/support/bootstrap.js +85 -0
- package/interfaces/semantic/support/fixtures/crud.fixture.js +66 -0
- package/interfaces/semantic/support/fixtures/validations.fixture.js +23 -0
- package/interfaces/semantic/types/array.type.js +28 -0
- package/interfaces/semantic/types/binary.type.js +34 -0
- package/interfaces/semantic/types/boolean.type.js +80 -0
- package/interfaces/semantic/types/date.type.js +53 -0
- package/interfaces/semantic/types/datetime.type.js +48 -0
- package/interfaces/semantic/types/float.type.js +40 -0
- package/interfaces/semantic/types/integer.type.js +40 -0
- package/interfaces/semantic/types/json.type.js +29 -0
- package/interfaces/semantic/types/string.type.js +40 -0
- package/interfaces/semantic/types/text.type.js +34 -0
- package/interfaces/semantic/types/time.type.js +52 -0
- package/interfaces/semantic/update.test.js +157 -0
- package/interfaces/sql/find.test.js +73 -0
- package/interfaces/sql/query.test.js +40 -0
- package/interfaces/sql/support/bootstrap.js +82 -0
- package/interfaces/sql/support/fixtures/crud.fixture.js +57 -0
- package/interfaces/transactable/commit.test.js +438 -0
- package/interfaces/transactable/crossAdapter.test.js +346 -0
- package/interfaces/transactable/deep.test.js +100 -0
- package/interfaces/transactable/rollback.test.js +221 -0
- package/interfaces/transactable/support/bootstrap.js +55 -0
- package/interfaces/transactable/support/bootstrapFn.js +51 -0
- package/interfaces/transactable/support/fixtures/customer.fixture.js +29 -0
- package/interfaces/transactable/support/fixtures/payment.fixture.js +24 -0
- package/interfaces/transactable/support/fixtures/receipt.fixture.js +20 -0
- package/interfaces/transactable/support/fixtures/store.fixture.js +22 -0
- package/interfaces/transactable/support/fixtures/storecustomer.fixture.js +14 -0
- package/lib/index.js +155 -0
- package/lib/utils.js +39 -0
- package/package.json +58 -4
- package/test/integration/README.md +26 -0
- package/test/integration/config/offshore-memory.js +8 -0
- package/test/integration/config/offshore-sql-mariadb.js +15 -0
- package/test/integration/config/offshore-sql-mysql.js +21 -0
- package/test/integration/config/offshore-sql-oracle.js +19 -0
- package/test/integration/config/offshore-sql-postgres.js +27 -0
- package/test/integration/config/offshore-sql-sqlite3.js +19 -0
- package/test/integration/runner.js +83 -0
- package/test/integration/runnerDispatcher.js +163 -0
- package/test/load/README.md +20 -0
- package/test/load/index.js +33 -0
- package/test/load/runner.js +160 -0
- package/test/load/support/bootstrap.js +69 -0
- package/test/load/support/fixtures/pet.js +8 -0
- package/test/load/support/fixtures/user.js +9 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test runner dependencies
|
|
3
|
+
*/
|
|
4
|
+
var util = require('util');
|
|
5
|
+
var mocha = require('mocha');
|
|
6
|
+
|
|
7
|
+
var adapterName = process.env.ADAPTER_NAME || process.argv[2];
|
|
8
|
+
var TestRunner = require('../../lib');
|
|
9
|
+
var settings = {};
|
|
10
|
+
try {
|
|
11
|
+
settings = require('./config/' + adapterName);
|
|
12
|
+
} catch(e){
|
|
13
|
+
console.warn("Warning: couldn't find config file for " + adapterName + ".");
|
|
14
|
+
}
|
|
15
|
+
var Adapter = settings.adapter;
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
console.info('Testing `' + settings.name + '`, a Offshore adapter.');
|
|
19
|
+
console.info('Running `offshore-adapter-tests` against ' + settings.interfaces.length + ' interfaces...');
|
|
20
|
+
console.info('( ' + settings.interfaces.join(', ') + ' )');
|
|
21
|
+
if (settings.features.length) {
|
|
22
|
+
console.info('and against ' + settings.features.length + ' feature tests...');
|
|
23
|
+
console.info('( ' + settings.features.join(', ') + ' )');
|
|
24
|
+
}
|
|
25
|
+
console.log();
|
|
26
|
+
console.log('Latest draft of Offshore adapter interface spec:');
|
|
27
|
+
console.log();
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Integration Test Runner
|
|
32
|
+
*
|
|
33
|
+
* Uses the `offshore-adapter-tests` module to
|
|
34
|
+
* run mocha tests against the specified interfaces
|
|
35
|
+
* of the currently-implemented Offshore adapter API.
|
|
36
|
+
*/
|
|
37
|
+
new TestRunner({
|
|
38
|
+
|
|
39
|
+
// Load the adapter module.
|
|
40
|
+
adapter: Adapter,
|
|
41
|
+
|
|
42
|
+
// Default adapter config to use.
|
|
43
|
+
config: settings.config,
|
|
44
|
+
|
|
45
|
+
// The set of adapter interfaces to test against.
|
|
46
|
+
// (grabbed these from this adapter's package.json file above)
|
|
47
|
+
interfaces: settings.interfaces,
|
|
48
|
+
|
|
49
|
+
// The set of adapter features to test against.
|
|
50
|
+
// (grabbed these from this adapter's package.json file above)
|
|
51
|
+
features: settings.features,
|
|
52
|
+
|
|
53
|
+
// Mocha options
|
|
54
|
+
// reference: https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically
|
|
55
|
+
mocha: {
|
|
56
|
+
reporter: 'spec'
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
mochaChainableMethods: {},
|
|
60
|
+
|
|
61
|
+
// Return code != 0 if any test failed
|
|
62
|
+
failOnError: true,
|
|
63
|
+
|
|
64
|
+
childProcess: true
|
|
65
|
+
|
|
66
|
+
// Most databases implement 'semantic' and 'queryable'.
|
|
67
|
+
//
|
|
68
|
+
// As of Offshore, the 'associations' interface
|
|
69
|
+
// is also available. If you don't implement 'associations',
|
|
70
|
+
// it will be polyfilled for you by Offshore core. The core
|
|
71
|
+
// implementation will always be used for cross-adapter / cross-connection
|
|
72
|
+
// joins.
|
|
73
|
+
//
|
|
74
|
+
// In future versions of Offshore, 'queryable' may be also
|
|
75
|
+
// be polyfilled by core.
|
|
76
|
+
//
|
|
77
|
+
// These polyfilled implementations can usually be further optimized at the
|
|
78
|
+
// adapter level, since most databases provide optimizations for internal
|
|
79
|
+
// operations.
|
|
80
|
+
//
|
|
81
|
+
// Full interface reference:
|
|
82
|
+
// https://github.com/balderdashy/sails-docs/blob/master/contributing/adapter-specification.md
|
|
83
|
+
});
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
var child_process = require('child_process');
|
|
2
|
+
var asynk = require('asynk');
|
|
3
|
+
var npm = require('npm');
|
|
4
|
+
var jpath = require('jpath');
|
|
5
|
+
var fs = require('fs');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
/////////////////////////////////////////////////////////////////////
|
|
9
|
+
//
|
|
10
|
+
// Config
|
|
11
|
+
|
|
12
|
+
// The adapters being tested
|
|
13
|
+
var adapters = [];
|
|
14
|
+
fs.readdirSync(__dirname + '/config').forEach(function(adapter) {
|
|
15
|
+
var config = require('./config/' + adapter);
|
|
16
|
+
config.fileName = adapter.slice(0, -3);
|
|
17
|
+
adapters.push(config);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// Core modules npm Dependencies path
|
|
21
|
+
var coreModulesPaths = {
|
|
22
|
+
"offshore": ".dependencies.offshore",
|
|
23
|
+
"- offshore-validator": ".dependencies.offshore.dependencies.offshore-validator",
|
|
24
|
+
"- offshore-schema": ".dependencies.offshore.dependencies.offshore-schema",
|
|
25
|
+
"offshore-adapter-tests": "."
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
//
|
|
30
|
+
/////////////////////////////////////////////////////////////////////
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
var status = {};
|
|
34
|
+
var npmData;
|
|
35
|
+
var exitCode = 0;
|
|
36
|
+
process.env.FORCE_COLORS = true;
|
|
37
|
+
|
|
38
|
+
console.time('total time elapsed');
|
|
39
|
+
|
|
40
|
+
var resultTable = "\n";
|
|
41
|
+
resultTable += " ------------------------------------------------------------------------------------- \n";
|
|
42
|
+
resultTable += "| adapter | version | result | failed | total | time |\n";
|
|
43
|
+
resultTable += "|----------------------------|---------|--------|--------|-------|--------------------|\n";
|
|
44
|
+
|
|
45
|
+
function getNpmDetails(cb){
|
|
46
|
+
npm.load({ depth: 2 }, function (er) {
|
|
47
|
+
if (er) return process.exit(1);
|
|
48
|
+
|
|
49
|
+
npm.commands.ls('', true, function(err, data){
|
|
50
|
+
npmData = data;
|
|
51
|
+
cb(err, data);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function runTests(cb){
|
|
57
|
+
asynk.each(adapters, function(adapter, next){
|
|
58
|
+
var adapterName = adapter.name;
|
|
59
|
+
var settings = adapter.config;
|
|
60
|
+
status[adapterName] = { passed: 0, failed: 0, total: 0, exitCode: 0, startTime: new Date().getTime() };
|
|
61
|
+
|
|
62
|
+
console.log("\n");
|
|
63
|
+
console.log("\033[0;34m-------------------------------------------------------------------------------------------\033[0m");
|
|
64
|
+
console.log("\033[0;34m %s \033[0m", adapterName);
|
|
65
|
+
console.log("\033[0;34m-------------------------------------------------------------------------------------------\033[0m");
|
|
66
|
+
console.log();
|
|
67
|
+
|
|
68
|
+
var child = child_process.fork('./test/integration/runner.js', [adapter.fileName], { env: process.env });
|
|
69
|
+
|
|
70
|
+
child.on('message', function(msg) {
|
|
71
|
+
status[adapterName].total++;
|
|
72
|
+
if (msg.state === 'passed') {
|
|
73
|
+
status[adapterName].passed++;
|
|
74
|
+
} else {
|
|
75
|
+
status[adapterName].failed++;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
child.on('close', function(code) {
|
|
80
|
+
status[adapterName].exitCode = code;
|
|
81
|
+
var message = code == 0 ? "\033[0;32mpassed\033[0m" : "\033[0;31mfailed\033[0m";
|
|
82
|
+
resultTable += "| " + padRight(adapterName, 26)
|
|
83
|
+
+ " | " + padLeft(processVersion(npmData.dependencies[adapterName]), 7)
|
|
84
|
+
+ " | " + message
|
|
85
|
+
+ " | " + padLeft(status[adapterName].failed, 6)
|
|
86
|
+
+ " | " + padLeft(status[adapterName].total, 5)
|
|
87
|
+
+ " | " + padLeft((new Date().getTime() - status[adapterName].startTime) + ' ms', 18)
|
|
88
|
+
+ " |\n";
|
|
89
|
+
|
|
90
|
+
console.log('exit code: ' + code);
|
|
91
|
+
if(code != 0 && (!settings || !settings.returnZeroOnError)) { exitCode = exitCode + code; }
|
|
92
|
+
next();
|
|
93
|
+
});
|
|
94
|
+
}).serie().asCallback(cb);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function printCoreModulesVersions(cb){
|
|
98
|
+
var coreModules = "\n";
|
|
99
|
+
coreModules += " ----------------------------------- \n";
|
|
100
|
+
coreModules += "| core modules | version |\n";
|
|
101
|
+
coreModules += "|-------------------------|---------|\n";
|
|
102
|
+
for(var moduleName in coreModulesPaths){
|
|
103
|
+
coreModules += getModuleRow(moduleName, jpath(npmData, coreModulesPaths[moduleName])[0]);
|
|
104
|
+
}
|
|
105
|
+
coreModules += " ----------------------------------- \n";
|
|
106
|
+
console.log(coreModules);
|
|
107
|
+
cb();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function getModuleRow(name, module){;
|
|
111
|
+
return "| "+ padRight(name, 23) + " | "
|
|
112
|
+
+ padLeft(processVersion(module), 7)
|
|
113
|
+
+ " |\n";
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
asynk.add(getNpmDetails).add(runTests).add(printCoreModulesVersions).serie().asCallback(function(err, res){
|
|
117
|
+
resultTable += " ------------------------------------------------------------------------------------- \n";
|
|
118
|
+
console.log(resultTable);
|
|
119
|
+
console.timeEnd('total time elapsed');
|
|
120
|
+
if(err){
|
|
121
|
+
console.error('Something wrong happened:', err);
|
|
122
|
+
}
|
|
123
|
+
process.exit(exitCode);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Aux functions
|
|
128
|
+
*/
|
|
129
|
+
|
|
130
|
+
function padRight(str, padding){
|
|
131
|
+
var res = "" + str;
|
|
132
|
+
for(var i=res.length; i<padding; i++){
|
|
133
|
+
res += ' ';
|
|
134
|
+
}
|
|
135
|
+
return res;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function padLeft(str, padding){
|
|
139
|
+
str = str + "";
|
|
140
|
+
var pad = "";
|
|
141
|
+
for(var i=str.length; i<padding; i++){
|
|
142
|
+
pad += ' ';
|
|
143
|
+
}
|
|
144
|
+
return pad + str;
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
function processVersion(dependency){
|
|
148
|
+
if(!dependency) return '';
|
|
149
|
+
if(dependency._resolved){
|
|
150
|
+
if(dependency._resolved.indexOf('git') === 0){
|
|
151
|
+
var parts = dependency._resolved.split('#');
|
|
152
|
+
return parts[parts.length-1].slice(0, 7);
|
|
153
|
+
}
|
|
154
|
+
if(dependency._resolved.indexOf('npmjs.org') >= 0){
|
|
155
|
+
return dependency.version;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if(dependency.gitHead){
|
|
159
|
+
return dependency.gitHead.slice(0, 7);
|
|
160
|
+
}
|
|
161
|
+
// console.warn('WARN: Not sure we found the dependency that was resolved.');
|
|
162
|
+
return dependency.version;
|
|
163
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Load tests
|
|
2
|
+
==========
|
|
3
|
+
A script that measures the memory comsumption of offshore under load, using the official adapters.
|
|
4
|
+
|
|
5
|
+
## Goal
|
|
6
|
+
Provide a tool to reliably measure performance of offshore and its adapters. Before pushing any changes
|
|
7
|
+
upstream it's a good idea to check if the performance has not deteriorated.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
### Run against all official adapters
|
|
12
|
+
``` shell
|
|
13
|
+
npm run test-load
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
### Run against chosen adapters
|
|
17
|
+
Example:
|
|
18
|
+
``` shell
|
|
19
|
+
npm run test-load -- sails-memory sails-disk
|
|
20
|
+
```
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
var exec = require('child_process').exec;
|
|
2
|
+
var asynk = require('asynk');
|
|
3
|
+
|
|
4
|
+
var adapters = ['offshore-sql', 'offshore-memory'];
|
|
5
|
+
if (process.argv.length > 2) {
|
|
6
|
+
adapters = process.argv.splice(2);
|
|
7
|
+
}
|
|
8
|
+
console.log('About to test ' + adapters + ' ...');
|
|
9
|
+
|
|
10
|
+
console.time('total time elapsed');
|
|
11
|
+
|
|
12
|
+
asynk.each(adapters, function(adapterName, next){
|
|
13
|
+
console.log("\n");
|
|
14
|
+
console.log("\033[0;34m-------------------------------------------------------------------------------------------\033[0m");
|
|
15
|
+
console.log("\033[0;34m %s \033[0m", adapterName);
|
|
16
|
+
console.log("\033[0;34m-------------------------------------------------------------------------------------------\033[0m");
|
|
17
|
+
console.log();
|
|
18
|
+
|
|
19
|
+
var child = exec('node ./test/load/runner.js ' + adapterName);
|
|
20
|
+
child.stdout.on('data', function(data){
|
|
21
|
+
process.stdout.write(data);
|
|
22
|
+
});
|
|
23
|
+
child.stderr.on('data', function(data){
|
|
24
|
+
process.stdout.write(data);
|
|
25
|
+
});
|
|
26
|
+
child.on('close', function(code) {
|
|
27
|
+
console.log('closing code: ' + code);
|
|
28
|
+
next();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
}).serie().asCallback(function allDone(err, results){
|
|
32
|
+
console.timeEnd('total time elapsed');
|
|
33
|
+
});
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Module dependencies
|
|
3
|
+
*/
|
|
4
|
+
var setupWaterline = require('./support/bootstrap');
|
|
5
|
+
var asynk = require('asynk');
|
|
6
|
+
var _ = require('lodash');
|
|
7
|
+
var adapterName = process.env.ADAPTER_NAME || process.argv[2];
|
|
8
|
+
var config = {};
|
|
9
|
+
try {
|
|
10
|
+
config = require('../integration/config/' + adapterName + '.json').config;
|
|
11
|
+
} catch(e){
|
|
12
|
+
console.log('Failed to load config for ' + adapterName + ', will use default.');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
var usersNumber = process.env.USERS_NUMBER || 3;
|
|
16
|
+
var petsNumber = process.env.PETS_NUMBER || 100;
|
|
17
|
+
var hitsNumber = process.env.HITS_NUMBER || 100;
|
|
18
|
+
var reportFreq = process.env.REPORT_FREQ || 10;
|
|
19
|
+
|
|
20
|
+
var measurements = [];
|
|
21
|
+
var connections = { 'load_test': config };
|
|
22
|
+
connections.load_test.adapter = 'default';
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
var offshore = setupWaterline({
|
|
26
|
+
adapters: {
|
|
27
|
+
'default': require(adapterName)
|
|
28
|
+
},
|
|
29
|
+
collections: {
|
|
30
|
+
user: require('./support/fixtures/user'),
|
|
31
|
+
pet: require('./support/fixtures/pet'),
|
|
32
|
+
},
|
|
33
|
+
connections: connections
|
|
34
|
+
}, function waterlineReady (err, ontology) {
|
|
35
|
+
if (err) throw err;
|
|
36
|
+
console.log('offshore initialized');
|
|
37
|
+
|
|
38
|
+
// Our collections (i.e. models):
|
|
39
|
+
global.WL_MODELS = ontology.collections;
|
|
40
|
+
|
|
41
|
+
boostrapCollections(function(err){
|
|
42
|
+
if(err) { handleError(err, 'failed to populate collections'); }
|
|
43
|
+
console.log('collections created');
|
|
44
|
+
|
|
45
|
+
process.stdout.write('\nHitting the db with ' + hitsNumber + ' requests...');
|
|
46
|
+
console.time('time elapsed');
|
|
47
|
+
|
|
48
|
+
loadTest(function(err){
|
|
49
|
+
console.log();
|
|
50
|
+
if(err) { handleError(err, 'failed to perform load test'); }
|
|
51
|
+
|
|
52
|
+
console.timeEnd('time elapsed');
|
|
53
|
+
console.log();
|
|
54
|
+
|
|
55
|
+
// stay idle and then check memory
|
|
56
|
+
setTimeout(function(){
|
|
57
|
+
console.log('idle: ' + reportMemory(process.memoryUsage()) + '\n');
|
|
58
|
+
printStats(measurements);
|
|
59
|
+
|
|
60
|
+
tearDown(ontology.collections, function(err){
|
|
61
|
+
if(err) { handleError(err, 'failed to teardown adapter'); }
|
|
62
|
+
console.log('collections teardown done');
|
|
63
|
+
|
|
64
|
+
process.exit(0);
|
|
65
|
+
});
|
|
66
|
+
}, 1000);
|
|
67
|
+
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
function loadTest(cb){
|
|
76
|
+
|
|
77
|
+
var memUsage = process.memoryUsage();
|
|
78
|
+
measurements.push(memUsage);
|
|
79
|
+
process.stdout.write('\n 0: ' + reportMemory(memUsage));
|
|
80
|
+
var n = 0;
|
|
81
|
+
|
|
82
|
+
function findAndPopulate (item, next) {
|
|
83
|
+
WL_MODELS.pet.find().populate('owner')
|
|
84
|
+
.then(function(){
|
|
85
|
+
n++;
|
|
86
|
+
if(n % reportFreq === 0){
|
|
87
|
+
var memUsage = process.memoryUsage();
|
|
88
|
+
measurements.push(memUsage);
|
|
89
|
+
process.stdout.write('\n' + n + ': ' + reportMemory(memUsage));
|
|
90
|
+
} else {
|
|
91
|
+
process.stdout.write(' .');
|
|
92
|
+
}
|
|
93
|
+
next();
|
|
94
|
+
})
|
|
95
|
+
.catch(next);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
asynk.each(_.range(1, hitsNumber+1), findAndPopulate).serie().asCallback(cb);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function reportMemory(memUsage){
|
|
102
|
+
return 'rss: ' + roundMB(memUsage.rss)
|
|
103
|
+
+ ' MB, heapTotal: ' + roundMB(memUsage.heapTotal)
|
|
104
|
+
+ ' MB, heapUsed: ' + roundMB(memUsage.heapUsed)
|
|
105
|
+
+ ' MB';
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function roundMB(num){
|
|
109
|
+
return (num/1e6).toFixed(2);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function printStats(stats){
|
|
113
|
+
var maxRss = _.max(_.map(stats, 'rss'));
|
|
114
|
+
var maxHeapTotal = _.max(_.map(stats, 'heapTotal'));
|
|
115
|
+
var maxHeapUsed = _.max(_.map(stats, 'heapUsed'));
|
|
116
|
+
console.log('max: ' + reportMemory({ rss: maxRss, heapTotal: maxHeapTotal, heapUsed: maxHeapUsed }));
|
|
117
|
+
|
|
118
|
+
var avgRss = _.reduce(_.map(stats, 'rss'), function(sum, num) { return sum + num; }) / stats.length;
|
|
119
|
+
var avgHeapTotal = _.reduce(_.map(stats, 'heapTotal'), function(sum, num) { return sum + num; }) / stats.length;
|
|
120
|
+
var avgHeapUsed = _.reduce(_.map(stats, 'heapUsed'), function(sum, num) { return sum + num; }) / stats.length;
|
|
121
|
+
console.log('avg: ' + reportMemory({ rss: avgRss, heapTotal: avgHeapTotal, heapUsed: avgHeapUsed }) + '\n');
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function boostrapCollections(cb){
|
|
125
|
+
asynk.each(_.range(0, usersNumber), function (userIndex, innerCb) {
|
|
126
|
+
WL_MODELS.user.create().exec(function (err, user) {
|
|
127
|
+
if (err) {
|
|
128
|
+
return innerCb(err);
|
|
129
|
+
}
|
|
130
|
+
asynk.each(_.range(0, petsNumber), function (petIndex, innerInnerCb) {
|
|
131
|
+
WL_MODELS.pet.create({ owner: user.id }).exec(innerInnerCb);
|
|
132
|
+
}).serie().asCallback(innerCb);
|
|
133
|
+
});
|
|
134
|
+
}).serie().asCallback(cb);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function handleError(err, message){
|
|
138
|
+
console.error(message);
|
|
139
|
+
console.error(err);
|
|
140
|
+
process.exit(1);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function tearDown(collections, cb){
|
|
144
|
+
|
|
145
|
+
function dropCollection(item, next) {
|
|
146
|
+
collections[item].drop(function(err) {
|
|
147
|
+
if(err) return next(err);
|
|
148
|
+
next();
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
asynk.each(Object.keys(collections), dropCollection).serie().asCallback(function(err) {
|
|
153
|
+
if (err) {
|
|
154
|
+
console.log('ERROR:', err);
|
|
155
|
+
cb(err);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
offshore.teardown(cb);
|
|
159
|
+
});
|
|
160
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Module dependencies
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
var _ = require('lodash');
|
|
6
|
+
var Offshore = require(process.env.offshorePath || 'offshore');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Set up Offshore with the specified
|
|
11
|
+
* models, connections, and adapters.
|
|
12
|
+
|
|
13
|
+
@param options
|
|
14
|
+
:: {Object} adapters [i.e. a dictionary]
|
|
15
|
+
:: {Object} connections [i.e. a dictionary]
|
|
16
|
+
:: {Object} collections [i.e. a dictionary]
|
|
17
|
+
|
|
18
|
+
@param {Function} cb
|
|
19
|
+
() {Error} err
|
|
20
|
+
() ontology
|
|
21
|
+
:: {Object} collections
|
|
22
|
+
:: {Object} connections
|
|
23
|
+
|
|
24
|
+
@return {Offshore}
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
module.exports = function bootstrap( options, cb ) {
|
|
28
|
+
|
|
29
|
+
var adapters = options.adapters || {};
|
|
30
|
+
var connections = options.connections || {};
|
|
31
|
+
var collections = options.collections || {};
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
_(adapters).each(function (def, identity) {
|
|
36
|
+
// Make sure our adapter defs have `identity` properties
|
|
37
|
+
def.identity = def.identity || identity;
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
var extendedCollections = [];
|
|
42
|
+
_(collections).each(function (def, identity) {
|
|
43
|
+
|
|
44
|
+
// Make sure our collection defs have `identity` properties
|
|
45
|
+
def.identity = def.identity || identity;
|
|
46
|
+
|
|
47
|
+
// Fold object of collection definitions into an array
|
|
48
|
+
// of extended Offshore collections.
|
|
49
|
+
extendedCollections.push(Offshore.Collection.extend(def));
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
// Instantiate Offshore and load the already-extended
|
|
54
|
+
// Offshore collections.
|
|
55
|
+
var offshore = new Offshore();
|
|
56
|
+
extendedCollections.forEach(function (collection) {
|
|
57
|
+
offshore.loadCollection(collection);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
// Initialize Offshore
|
|
62
|
+
// (and tell it about our adapters)
|
|
63
|
+
offshore.initialize({
|
|
64
|
+
adapters: adapters,
|
|
65
|
+
connections: connections
|
|
66
|
+
}, cb);
|
|
67
|
+
|
|
68
|
+
return offshore;
|
|
69
|
+
};
|