Skip to content

Commit c16f744

Browse files
committed
Refactor for completely parallel tests.
1 parent 89d2937 commit c16f744

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1141
-1348
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ test/encrypted/nodejs-docs-samples.json
66
dump.rdb
77
logs/
88
*.iml
9-
.idea/
9+
.idea/
10+
.nyc_output

.travis.yml

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ cache:
3939
- appengine/mailgun/node_modules/
4040
- appengine/memcached/node_modules/
4141
- appengine/mongodb/node_modules/
42+
- appengine/parse-server/node_modules/
43+
- appengine/pubsub/node_modules/
4244
- appengine/redis/node_modules/
4345
- appengine/restify/node_modules/
4446
- appengine/sails/node_modules/
@@ -50,7 +52,9 @@ cache:
5052
- appengine/websockets/node_modules/
5153
- computeengine/sendgrid/node_modules/
5254
- datastore/node_modules/
55+
- functions/uuid/node_modules/
5356
- logging/node_modules/
57+
- monitoring/node_modules/
5458
- prediction/node_modules/
5559
- pubsub/node_modules/
5660
- storage/node_modules/
@@ -61,26 +65,13 @@ services:
6165

6266
env:
6367
global:
64-
- PATH=$PATH:$HOME/gcloud/google-cloud-sdk/bin
6568
- GOOGLE_APPLICATION_CREDENTIALS=$TRAVIS_BUILD_DIR/test/encrypted/nodejs-docs-samples.json
6669
- TEST_BUCKET_NAME=nodejs-docs-samples
6770
- GCLOUD_PROJECT=nodejs-docs-samples
6871

6972
before_install:
70-
- if [ ! -d $HOME/gcloud/google-cloud-sdk ]; then
71-
mkdir -p $HOME/gcloud &&
72-
wget https://dl.google.com/dl/cloudsdk/channels/rapid/google-cloud-sdk.tar.gz --directory-prefix=$HOME/gcloud &&
73-
cd $HOME/gcloud &&
74-
tar xzf google-cloud-sdk.tar.gz &&
75-
printf '\ny\n\ny\ny\n' | ./google-cloud-sdk/install.sh &&
76-
source $HOME/.bashrc &&
77-
cd $TRAVIS_BUILD_DIR;
78-
fi
7973
- openssl aes-256-cbc -K $encrypted_fda0b707c7d5_key -iv $encrypted_fda0b707c7d5_iv -in test/encrypted/nodejs-docs-samples.json.enc -out test/encrypted/nodejs-docs-samples.json -d
80-
- if [ -a test/encrypted/nodejs-docs-samples.json ]; then
81-
gcloud auth activate-service-account --key-file test/encrypted/nodejs-docs-samples.json;
82-
fi
8374
- npm set progress=false
8475

8576
after_success:
86-
- npm run coveralls
77+
- npm run report

README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,30 +129,29 @@ a service account file. You can download one from your Google project's
129129
"permissions" page.
130130
1. `npm test`
131131

132-
Since the tests use [Mocha.js](https://mochajs.org/), you can use the `--grep`
133-
option to run only the tests that match a provided pattern. The `--invert`
134-
option causes the matched tests to be excluded instead of included.
132+
Since the tests use [AVA](https://github.com/sindresorhus/ava), you can use the
133+
`--match` option to run only the tests that match a provided pattern.
135134

136135
__Run only the tests that match a pattern:__
137136

138137

139-
npm test -- -- --grep <pattern>
138+
npm test -- -- --match="<pattern>"
140139

141140
__Only run the tests for the `datastore` sample:__
142141

143-
npm test -- -- --grep datastore
142+
npm test -- -- --match="datastore"
144143

145144
__Skip the tests that match a pattern:__
146145

147-
npm test -- -- --grep <pattern> --invert
146+
npm test -- -- --match="!<pattern>"
148147

149148
__Run all but the `datastore` tests:__
150149

151-
npm test -- -- --grep datastore --invert
150+
npm test -- -- --match="!datastore"
152151

153152
__Skip the tests that require Redis and Memcached:__
154153

155-
npm test -- -- --grep "express-memcached-session|redis" --invert
154+
npm test -- -- --match="express-memcached-session|redis"
156155

157156
## License
158157

datastore/concepts.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -788,8 +788,7 @@ Query.prototype.testRunQueryProjection = function(callback) {
788788

789789
self.datastore.runQuery(query, function(err) {
790790
if (err) {
791-
callback(err);
792-
return;
791+
return callback(err);
793792
}
794793

795794
queryCallback.apply(null, arguments);
@@ -808,6 +807,7 @@ Query.prototype.testRunQueryProjection = function(callback) {
808807
var percentCompletes = [];
809808

810809
datastore.runQuery(query, function(err, tasks) {
810+
console.log(err, tasks);
811811
if (err) {
812812
// An error occurred while running the query.
813813
return;

datastore/error.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@ function runQuery(cb) {
5151
exports.runQuery = runQuery;
5252

5353
if (module === require.main) {
54-
runQuery(function () {});
54+
runQuery(console.log);
5555
}

logging/export.js

Lines changed: 64 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,70 +28,103 @@ var logging = gcloud.logging();
2828
// [END setup]
2929

3030
// [START listSinks]
31-
function listSinks(callback) {
31+
/**
32+
* @param {Function} callback Callback function.
33+
*/
34+
function listSinksExample(callback) {
3235
// list all sinks in the authenticated project
33-
logging.getSinks(callback);
36+
logging.getSinks(function (err, sinks) {
37+
if (err) {
38+
return callback(err);
39+
}
40+
41+
// Should have received all sinks
42+
console.log('Found ' + sinks.length + ' sinks');
43+
callback(null, sinks);
44+
});
3445
}
3546
// [END listSinks]
3647

3748
// [START createSink]
38-
function createSink(callback) {
39-
// Get a reference to the Cloud Storage component
40-
var gcs = gcloud.storage();
41-
49+
/**
50+
* @param {string} sinkName Name of the new sink.
51+
* @param {Object} config Configuration options for the new sink.
52+
* @param {Function} callback Callback function.
53+
*/
54+
function createSinkExample(sinkName, config, callback) {
4255
// create a new sink in the authenticated project
4356
//
4457
// This method only works if you are authenticated as yourself, e.g. using the
4558
// gcloud SDK.
46-
logging.createSink('mySink', {
47-
destination: gcs.bucket('logging-bucket')
48-
}, callback);
59+
logging.createSink(sinkName, config, function (err, sink, apiResponse) {
60+
if (err) {
61+
return callback(err);
62+
}
63+
64+
// Should have received newly created sink
65+
console.log('Created ' + sinkName, sink);
66+
callback(null, sink, apiResponse);
67+
});
4968
}
5069
// [END createSink]
5170

5271
// [START updateSink]
53-
function updateSink(callback) {
54-
// Get a reference to the Cloud Storage component
55-
var gcs = gcloud.storage();
72+
/**
73+
* @param {string} sinkName Name of the sink to update.
74+
* @param {Object} config New configuration options for the sink.
75+
* @param {Function} callback Callback function.
76+
*/
77+
function updateSinkExample(sinkName, config, callback) {
5678
// Get a reference to an existing sink
57-
var sink = logging.sink('mySink');
79+
var sink = logging.sink(sinkName);
5880

5981
// update a sink
6082
//
6183
// This method only works if you are authenticated as yourself, e.g. using the
6284
// gcloud SDK.
63-
sink.setMetadata({
64-
// change destination to something else
65-
destination: gcs.bucket('other-logging-bucket')
66-
}, callback);
85+
sink.setMetadata(config, function (err, apiResponse) {
86+
if (err) {
87+
return callback(err);
88+
}
89+
90+
console.log('Updated ' + sinkName);
91+
callback(null, apiResponse);
92+
});
6793
}
6894
// [END updateSink]
6995

7096
// [START deleteSink]
71-
function deleteSink(callback) {
97+
/**
98+
* @param {string} sinkName Name of the sink to delete.
99+
* @param {Function} callback Callback function.
100+
*/
101+
function deleteSinkExample(sinkName, callback) {
72102
// Get a reference to an existing sink
73-
var sink = logging.sink('mySink');
103+
var sink = logging.sink(sinkName);
74104

75105
// delete a sink
76106
//
77107
// This method only works if you are authenticated as yourself, e.g. using the
78108
// gcloud SDK.
79-
sink.delete(callback);
109+
sink.delete(function (err, apiResponse) {
110+
if (err) {
111+
return callback(err);
112+
}
113+
114+
console.log('Deleted ' + sinkName);
115+
callback(null, apiResponse);
116+
});
80117
}
81118
// [END deleteSink]
82119

83-
exports.runExample = function (cb) {
84-
listSinks(function (err, sinks, apiResponse) {
85-
console.log(err, 'sinks:', sinks, 'apiResponse:', apiResponse);
86-
if (typeof cb === 'function') {
87-
cb(err, sinks);
88-
}
89-
});
120+
// Run the examples
121+
exports.main = function (cb) {
122+
listSinksExample(cb || console.log);
90123
};
91-
exports.createSink = createSink;
92-
exports.updateSink = updateSink;
93-
exports.deleteSink = deleteSink;
124+
exports.createSinkExample = createSinkExample;
125+
exports.updateSinkExample = updateSinkExample;
126+
exports.deleteSinkExample = deleteSinkExample;
94127

95128
if (module === require.main) {
96-
exports.runExample();
129+
exports.main();
97130
}

logging/list.js

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,33 @@ var gcloud = require('gcloud')({
3030
// Get a reference to the logging component
3131
var logging = gcloud.logging();
3232

33-
function list(callback) {
34-
// Retrieve the latest 3 log entries from the authenticated project.
35-
logging.getEntries({
36-
pageSize: 3
37-
}, callback);
38-
}
39-
// [END list]
33+
/**
34+
* @param {Object} [options] Configuration options for the request.
35+
* @param {Function} callback Callback function.
36+
*/
37+
function listExample(options, callback) {
38+
if (typeof options === 'function') {
39+
callback = options;
40+
}
4041

41-
exports.runExample = function (cb) {
42-
console.log('retrieving latest 3 log entries...');
43-
list(function (err, entries, apiResponse) {
44-
console.log(err, 'entries:', entries, 'apiResponse:', apiResponse);
45-
if (typeof cb === 'function') {
46-
cb(err, entries, apiResponse);
42+
// Retrieve the latest some log entries from the authenticated project.
43+
logging.getEntries(options, function (err, entries, nextQuery, apiResponse) {
44+
if (err) {
45+
return callback(err);
4746
}
47+
48+
// Should have received some log entries
49+
console.log('Found ' + entries.length + ' entries');
50+
callback(null, entries, nextQuery, apiResponse);
4851
});
52+
}
53+
// [END list]
54+
55+
// Run the examples
56+
exports.main = function (options, cb) {
57+
listExample(options || { pageSize: 1 }, cb || console.log);
4958
};
5059

5160
if (module === require.main) {
52-
exports.runExample();
61+
exports.main();
5362
}

0 commit comments

Comments
 (0)