mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Test database failure reporting
This commit is contained in:
@@ -175,9 +175,8 @@ _.each(["insert", "update", "remove"], function (name) {
|
||||
// baffled if their writes don't work because their database is
|
||||
// down.
|
||||
callback = function (err) {
|
||||
if (err) {
|
||||
if (err)
|
||||
Meteor._debug(name + " failed: " + err.error + " -- " + err.reason);
|
||||
}
|
||||
};
|
||||
|
||||
if (name === "insert") {
|
||||
|
||||
@@ -93,6 +93,14 @@ _Mongo.prototype._maybeBeginWrite = function () {
|
||||
|
||||
_Mongo.prototype.insert = function (collection_name, document) {
|
||||
var self = this;
|
||||
|
||||
if (collection_name === "___meteor_failure_test_collection" &&
|
||||
document.fail) {
|
||||
var e = new Error("Failure test");
|
||||
e.expected = true;
|
||||
throw e;
|
||||
}
|
||||
|
||||
var write = self._maybeBeginWrite();
|
||||
|
||||
var finish = Meteor.bindEnvironment(function () {
|
||||
@@ -127,6 +135,14 @@ _Mongo.prototype.insert = function (collection_name, document) {
|
||||
|
||||
_Mongo.prototype.remove = function (collection_name, selector) {
|
||||
var self = this;
|
||||
|
||||
if (collection_name === "___meteor_failure_test_collection" &&
|
||||
selector.fail) {
|
||||
var e = new Error("Failure test");
|
||||
e.expected = true;
|
||||
throw e;
|
||||
}
|
||||
|
||||
var write = self._maybeBeginWrite();
|
||||
|
||||
var finish = Meteor.bindEnvironment(function () {
|
||||
@@ -164,6 +180,14 @@ _Mongo.prototype.remove = function (collection_name, selector) {
|
||||
|
||||
_Mongo.prototype.update = function (collection_name, selector, mod, options) {
|
||||
var self = this;
|
||||
|
||||
if (collection_name === "___meteor_failure_test_collection" &&
|
||||
selector.fail) {
|
||||
var e = new Error("Failure test");
|
||||
e.expected = true;
|
||||
throw e;
|
||||
}
|
||||
|
||||
var write = self._maybeBeginWrite();
|
||||
|
||||
var finish = Meteor.bindEnvironment(function () {
|
||||
|
||||
34
packages/mongo-livedata/mongo_livedata_tests.js
Normal file
34
packages/mongo-livedata/mongo_livedata_tests.js
Normal file
@@ -0,0 +1,34 @@
|
||||
// This is a magic collection that fails its writes on the server when
|
||||
// the selector (or inserted document) contains fail: true.
|
||||
|
||||
// XXX namespacing
|
||||
Meteor._FailureTestCollection =
|
||||
new Meteor.Collection("___meteor_failure_test_collection");
|
||||
|
||||
testAsyncMulti("mongo-livedata - database failure reporting", [
|
||||
function (test, expect) {
|
||||
var ftc = Meteor._FailureTestCollection;
|
||||
|
||||
var exception = function (err) {
|
||||
test.instanceOf(err, Error);
|
||||
};
|
||||
|
||||
_.each(["insert", "remove", "update"], function (op) {
|
||||
if (Meteor.is_server) {
|
||||
test.throws(function () {
|
||||
ftc[op]({fail: true});
|
||||
});
|
||||
|
||||
ftc[op]({fail: true}, expect(exception));
|
||||
}
|
||||
|
||||
if (Meteor.is_client) {
|
||||
ftc[op]({fail: true}, expect(exception));
|
||||
|
||||
// This would log to console in normal operation.
|
||||
Meteor._suppress_log(1);
|
||||
ftc[op]({fail: true});
|
||||
}
|
||||
});
|
||||
}
|
||||
]);
|
||||
@@ -21,3 +21,9 @@ Package.on_use(function (api) {
|
||||
api.add_files('remote_collection_driver.js', 'server');
|
||||
api.add_files('collection.js', ['client', 'server']);
|
||||
});
|
||||
|
||||
Package.on_test(function (api) {
|
||||
api.use('mongo-livedata');
|
||||
api.use('tinytest');
|
||||
api.add_files('mongo_livedata_tests.js', ['client', 'server']);
|
||||
});
|
||||
Reference in New Issue
Block a user