From b16d0fa0a0bad1edba8df3af8c7eba5a3ba79c68 Mon Sep 17 00:00:00 2001 From: Zhuohuan LI Date: Tue, 21 Jun 2016 21:27:46 +0800 Subject: [PATCH] mute warn log for watchDogReset unit test --- src/puppet-web.js | 4 ++-- test/puppet-web-spec.js | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/puppet-web.js b/src/puppet-web.js index 97b0108b..54e0f29a 100644 --- a/src/puppet-web.js +++ b/src/puppet-web.js @@ -89,7 +89,7 @@ class PuppetWeb extends Puppet { if (this.server) { yield this.server.quit() this.server = null - } else { log.warn('PuppetWeb', 'quit() without a server') } + } else { log.verbose('PuppetWeb', 'quit() without a server') } if (this.browser) { yield (this.browser.quit().catch(e => { // fail safe @@ -230,7 +230,7 @@ class PuppetWeb extends Puppet { } watchDogReset(timeout) { - log.warn('PuppetWeb', 'watchDogReset() timeout %d', timeout) + log.verbose('PuppetWeb', 'watchDogReset() timeout %d', timeout) const e = new Error('watchdog reset after ' + Math.floor(timeout/1000) + ' seconds') this.emit('error', e) return Event.onBrowserDead.call(this, e) diff --git a/test/puppet-web-spec.js b/test/puppet-web-spec.js index eba14ad4..b4c5c16e 100644 --- a/test/puppet-web-spec.js +++ b/test/puppet-web-spec.js @@ -27,7 +27,6 @@ test('PuppetWeb smoke testing', function(t) { m.set('from', EXPECTED_USER_ID) t.ok(pw.self(m), 'should identified self for message which from is self') - // XXX find a better way to mock... pw.bridge.getUserName = function() { return Promise.resolve('mockedUserName') } pw.getContact = function() { return Promise.resolve('dummy') } @@ -66,7 +65,7 @@ test('Puppet Web server/browser communication', function(t) { let pw = new PuppetWeb({port: PORT, head: HEAD, session: SESSION}) t.ok(pw, 'should instantiated a PuppetWeb') - const EXPECTED_DING_DATA='dingdong' + const EXPECTED_DING_DATA = 'dingdong' co(function* () { yield pw.init() @@ -143,7 +142,12 @@ test('Puppet Web watchdog timer', function(t) { const EXPECTED_DING_DATA = 'dingdong' pw.watchDog('feed to extend the dog life') + + const origLogLevel = log.level + log.level = 'silent' + t.ok('set log.level = silent to mute log when watchDog reset wechaty') const dong = yield waitDing(EXPECTED_DING_DATA) + log.level = origLogLevel t.equal(dong, EXPECTED_DING_DATA, 'should get EXPECTED_DING_DATA from ding after watchdog reset') }) .catch(e => { // Exception @@ -166,7 +170,7 @@ test('Puppet Web watchdog timer', function(t) { // timeout = 49,000 for {max: 7, backoff: 2000} const timeout = max * (backoff * max) / 2 - return retryPromise({ max: max, backoff: backoff }, function (attempt) { + return retryPromise({max: max, backoff: backoff}, function(attempt) { log.silly('TestPuppetWeb', 'waitDing() retryPromise: attampt %s/%s time for timeout %s' , attempt, max, timeout) return pw.ding(data) @@ -194,4 +198,4 @@ test('Puppet Web Self Message Identification', function(t) { t.ok(p, 'should instantiated a PuppetWeb') t.end() -}) \ No newline at end of file +}) -- GitLab