Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[fix test] Ensure that logs have flushed before attempting to query them

  • Loading branch information...
commit 3bfe86254b8b40a790a3c208f94ae0a20e836843 1 parent 2322f1b
Charlie Robbins indexzero authored

Showing 1 changed file with 105 additions and 100 deletions. Show diff stats Hide diff stats

  1. +105 100 test/transports/transport.js
205 test/transports/transport.js
@@ -47,106 +47,6 @@ module.exports = function (transport, options) {
47 47 assert.isNotNull(logged);
48 48 }
49 49 ),
50   - 'the query() method': {
51   - 'using basic querying': {
52   - 'topic': function (logger) {
53   - if (!transport.query) return;
54   - var cb = this.callback;
55   - logger.log('info', 'hello world', {}, function () {
56   - logger.query(cb);
57   - });
58   - },
59   - 'should return matching results': function (err, results) {
60   - if (!transport.query) return;
61   - assert.isNull(err);
62   - results = results[transport.name];
63   - while (!Array.isArray(results)) {
64   - results = results[Object.keys(results).pop()];
65   - }
66   - var log = results.pop();
67   - assert.ok(log.message.indexOf('hello world') === 0
68   - || log.message.indexOf('test message') === 0);
69   - }
70   - },
71   - 'using the `rows` option': {
72   - 'topic': function (logger) {
73   - if (!transport.query) return;
74   - var cb = this.callback;
75   - logger.log('info', 'hello world', {}, function () {
76   - logger.query({ rows: 1 }, cb);
77   - });
78   - },
79   - 'should return one result': function (err, results) {
80   - if (!transport.query) return;
81   - assert.isNull(err);
82   - results = results[transport.name];
83   - while (!Array.isArray(results)) {
84   - results = results[Object.keys(results).pop()];
85   - }
86   - assert.equal(results.length, 1);
87   - }
88   - },
89   - 'using `fields` and `order` option': {
90   - 'topic': function (logger) {
91   - if (!transport.query) return;
92   - var cb = this.callback;
93   - logger.log('info', 'hello world', {}, function () {
94   - logger.query({ order: 'asc', fields: ['timestamp'] }, cb);
95   - });
96   - },
97   - 'should return matching results': function (err, results) {
98   - if (!transport.query) return;
99   - assert.isNull(err);
100   - results = results[transport.name];
101   - while (!Array.isArray(results)) {
102   - results = results[Object.keys(results).pop()];
103   - }
104   - assert.equal(Object.keys(results[0]).length, 1);
105   - assert.ok(new Date(results.shift().timestamp)
106   - < new Date(results.pop().timestamp));
107   - }
108   - },
109   - 'using the `from` and `until` option': {
110   - 'topic': function (logger) {
111   - if (!transport.query) return;
112   - var cb = this.callback;
113   - var start = new Date - 100 * 1000;
114   - var end = new Date + 100 * 1000;
115   - logger.query({ from: start, until: end }, cb);
116   - },
117   - 'should return matching results': function (err, results) {
118   - if (!transport.query) return;
119   - assert.isNull(err);
120   - results = results[transport.name];
121   - while (!Array.isArray(results)) {
122   - results = results[Object.keys(results).pop()];
123   - }
124   - assert.ok(results.length >= 1);
125   - }
126   - },
127   - 'using a bad `from` and `until` option': {
128   - 'topic': function (logger) {
129   - if (!transport.query) return;
130   - var cb = this.callback;
131   - logger.log('info', 'bad from and until', {}, function () {
132   - var now = new Date + 1000000;
133   - logger.query({ from: now, until: now }, cb);
134   - });
135   - },
136   - 'should return no results': function (err, results) {
137   - if (!transport.query) return;
138   - assert.isNull(err);
139   - results = results[transport.name];
140   - while (!Array.isArray(results)) {
141   - results = results[Object.keys(results).pop()];
142   - }
143   - results = [results.filter(function(log) {
144   - return log.message === 'bad from and until';
145   - }).pop()];
146   - assert.isUndefined(results[0]);
147   - }
148   - }
149   - },
150 50 'the stream() method': {
151 51 'using no options': {
152 52 'topic': function () {
@@ -200,6 +100,111 @@ module.exports = function (transport, options) {
200 100 log.stream.destroy();
201 101 }
202 102 }
  103 + },
  104 + 'after the logs have flushed': {
  105 + topic: function () {
  106 + setTimeout(this.callback, 1000);
  107 + },
  108 + 'the query() method': {
  109 + 'using basic querying': {
  110 + 'topic': function () {
  111 + if (!transport.query) return;
  112 + var cb = this.callback;
  113 + logger.log('info', 'hello world', {}, function () {
  114 + logger.query(cb);
  115 + });
  116 + },
  117 + 'should return matching results': function (err, results) {
  118 + if (!transport.query) return;
  119 + assert.isNull(err);
  120 + results = results[transport.name];
  121 + while (!Array.isArray(results)) {
  122 + results = results[Object.keys(results).pop()];
  123 + }
  124 + var log = results.pop();
  125 + assert.ok(log.message.indexOf('hello world') === 0
  126 + || log.message.indexOf('test message') === 0);
  127 + }
  128 + },
  129 + 'using the `rows` option': {
  130 + 'topic': function () {
  131 + if (!transport.query) return;
  132 + var cb = this.callback;
  133 + logger.log('info', 'hello world', {}, function () {
  134 + logger.query({ rows: 1 }, cb);
  135 + });
  136 + },
  137 + 'should return one result': function (err, results) {
  138 + if (!transport.query) return;
  139 + assert.isNull(err);
  140 + results = results[transport.name];
  141 + while (!Array.isArray(results)) {
  142 + results = results[Object.keys(results).pop()];
  143 + }
  144 + assert.equal(results.length, 1);
  145 + }
  146 + },
  147 + 'using `fields` and `order` option': {
  148 + 'topic': function () {
  149 + if (!transport.query) return;
  150 + var cb = this.callback;
  151 + logger.log('info', 'hello world', {}, function () {
  152 + logger.query({ order: 'asc', fields: ['timestamp'] }, cb);
  153 + });
  154 + },
  155 + 'should return matching results': function (err, results) {
  156 + if (!transport.query) return;
  157 + assert.isNull(err);
  158 + results = results[transport.name];
  159 + while (!Array.isArray(results)) {
  160 + results = results[Object.keys(results).pop()];
  161 + }
  162 + assert.equal(Object.keys(results[0]).length, 1);
  163 + assert.ok(new Date(results.shift().timestamp)
  164 + < new Date(results.pop().timestamp));
  165 + }
  166 + },
  167 + 'using the `from` and `until` option': {
  168 + 'topic': function () {
  169 + if (!transport.query) return;
  170 + var cb = this.callback;
  171 + var start = new Date - 100 * 1000;
  172 + var end = new Date + 100 * 1000;
  173 + logger.query({ from: start, until: end }, cb);
  174 + },
  175 + 'should return matching results': function (err, results) {
  176 + if (!transport.query) return;
  177 + assert.isNull(err);
  178 + results = results[transport.name];
  179 + while (!Array.isArray(results)) {
  180 + results = results[Object.keys(results).pop()];
  181 + }
  182 + assert.ok(results.length >= 1);
  183 + }
  184 + },
  185 + 'using a bad `from` and `until` option': {
  186 + 'topic': function () {
  187 + if (!transport.query) return;
  188 + var cb = this.callback;
  189 + logger.log('info', 'bad from and until', {}, function () {
  190 + var now = new Date + 1000000;
  191 + logger.query({ from: now, until: now }, cb);
  192 + });
  193 + },
  194 + 'should return no results': function (err, results) {
  195 + if (!transport.query) return;
  196 + assert.isNull(err);
  197 + results = results[transport.name];
  198 + while (!Array.isArray(results)) {
  199 + results = results[Object.keys(results).pop()];
  200 + }
  201 + results = [results.filter(function(log) {
  202 + return log.message === 'bad from and until';
  203 + }).pop()];
  204 + assert.isUndefined(results[0]);
  205 + }
  206 + }
  207 + }
203 208 }
204 209 };
205 210

0 comments on commit 3bfe862

Please sign in to comment.
Something went wrong with that request. Please try again.