it.test(' -> should try to reconnect to rabbit on fail', t => { // create worker const master = new Microwork({host: `${host}:1234`, reconnectTimeout: 500}); // override connect function to make sure it's called second time master.connect = () => { t.ok(true, '# should try to reconnect'); t.end(); return new Promise(r => r()); }; });
t.test('should configure and install raven only once', (assert) => { const sentryMiddleware = SentryMiddleware() sentryMiddleware(event, context, nextStub) sentryMiddleware(event, context, nextStub) .then((returnValue) => { assert.same(returnValue, nextValue) sinon.assert.calledOnce(ravenStubs.config) sinon.assert.calledOnce(ravenStubs.install) assert.done() }) })
t.test('excludes false conflicts by default', function(t) { const o = 'AA ZZ'; const a = 'AA a b c ZZ'; const b = 'AA a b c ZZ'; const result = Diff3.diff3Merge(a, o, b); t.same(result[0].ok, ['AA', 'a', 'b', 'c', 'ZZ']); t.same(result[0].conflict, undefined); t.end(); });
t.test('should catch exception and pass it to sentry', (assert) => { const exception = new Error('Nasty Exception') ravenStubs.captureException.yields() const sentryMiddleware = SentryMiddleware() sentryMiddleware(event, context, () => Promise.reject(exception)) .catch((error) => { assert.same(error, exception) assert.ok(ravenStubs.captureException.called) assert.done() }) })
test('Logger instantiation', async (t) => { t.test('not using `new` returns instance anyway', async (tt) => { const log = Logger(apiKey, createOptions()) tt.equal(log.constructor.name, 'Logger', 'instance returned') }) t.test('Normal instantiation directly with Logger', async (tt) => { const log = new Logger(apiKey, createOptions()) tt.equal(log.constructor.name, 'Logger', 'instance returned') }) t.test('Intantiate via createLogger', async (tt) => { const log = logger.createLogger(apiKey, createOptions()) tt.equal(log.constructor.name, 'Logger', 'instance returned') }) })
t.test('more than one formatting error in title line', (tt) => { const v = new Validator({ 'validate-metadata': false }) v.lint(str9) v.on('commit', (data) => { const msgs = data.messages const filtered = msgs.filter((item) => { return item.level === 'fail' }) tt.equal(filtered.length, 2, 'messages.length') tt.end() }) })
t.test('should call next middleware and return', (assert) => { const sentryMiddleware = SentryMiddleware() sentryMiddleware(event, context, nextStub) .then((returnValue) => { assert.same(returnValue, 'Next') assert.ok(ravenStubs.config.called) assert.done() }) })
it.test(' -> should allow stopping while trying to reconnect to rabbit', t => { // create worker const master = new Microwork({host: `${host}:1234`, reconnectTimeout: 1000}); setTimeout(async () => { await master.stop(); t.ok(true, '# should stop connection retries'); t.end(); }, 100); });
t.test('should not add event source and source ARN to kwargs.extra if not available', (assert) => { const exception = new Error('Nasty Exception') const sentryMiddleware = SentryMiddleware() ravenStubs.captureException.yields() sentryMiddleware(event, context, () => Promise.reject(exception)) .catch((error) => { assert.same(error, exception) sinon.assert.calledWith( ravenStubs.captureException, sinon.match(exception), sinon.match({}), sinon.match.func ) assert.done() }) })
test('patch', function(t) { t.test('applies a patch against buffer1 to get buffer2', function(t) { const patch = Diff3.diffPatch(a, b); const result = Diff3.patch(a, patch); t.same(result, b); t.end(); }); t.test('did not modify buffer1 or buffer2', function(t) { t.strictSame(a0, a); t.strictSame(b0, b); t.end(); }); t.end(); });
t.test('avoids improper hunk sorting - see openstreetmap/iD#3058', function(t) { const a = ['n4100522632', 'n4100697091', 'n4100697136', 'n-10000', 'n4102671583', 'n4102671584', 'n4102671585', 'n4102671586', 'n4102671587', 'n4102671588', 'n4102677889', 'n4102677890', 'n4094374176']; const o = ['n4100522632', 'n4100697091', 'n4100697136', 'n4102671583', 'n4102671584', 'n4102671585', 'n4102671586', 'n4102671587', 'n4102671588', 'n4102677889', 'n4102677890', 'n4094374176']; const b = ['n4100522632', 'n4100697091', 'n4100697136', 'n4102671583', 'n4102671584', 'n4102671585', 'n4102671586', 'n4102671587', 'n4102671588', 'n4102677889', 'n4105613618', 'n4102677890', 'n4105613617', 'n4094374176']; const expected = ['n4100522632', 'n4100697091', 'n4100697136', 'n-10000', 'n4102671583', 'n4102671584', 'n4102671585', 'n4102671586', 'n4102671587', 'n4102671588', 'n4102677889', 'n4105613618', 'n4102677890', 'n4105613617', 'n4094374176']; const result = Diff3.diff3Merge(a, o, b); t.same(result[0].ok, expected); t.end(); });
t.test('should call middleware inside Raven.context', (assert) => { const sentryMiddleware = SentryMiddleware() sentryMiddleware(event, context, nextStub) .then((returnValue) => { assert.same(returnValue, 'Next') assert.ok(ravenStubs.context.called) assert.done() }) })