1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | var assert = require('assert'),
|
10 | fs = require('fs'),
|
11 | os = require('os'),
|
12 | path = require('path'),
|
13 | vows = require('vows'),
|
14 | winston = require('../../lib/winston');
|
15 |
|
16 | vows.describe('winston/transports/file').addBatch({
|
17 | 'A stressed instance of the File Transport': {
|
18 | topic: function () {
|
19 | var callback = this.callback.bind(this),
|
20 | logPath = path.resolve(__dirname, '../fixtures/logs/file-stress-test.log');
|
21 |
|
22 | try {
|
23 | fs.unlinkSync(logPath);
|
24 | } catch (ex) {
|
25 | if (ex && ex.code !== 'ENOENT') { return callback(ex); }
|
26 | }
|
27 |
|
28 | var fileTransport = new (winston.transports.File)({
|
29 | filename: logPath
|
30 | }),
|
31 | logger = new (winston.Logger)({
|
32 | transports: [fileTransport]
|
33 | });
|
34 |
|
35 | fileTransport.on('open', function () {
|
36 | setTimeout(function () {
|
37 | clearInterval(interval);
|
38 |
|
39 | logger.query({ order: 'asc' }, function (err, results) {
|
40 | callback(null, results);
|
41 | });
|
42 | }, 100);
|
43 | });
|
44 |
|
45 | var logIndex = 0,
|
46 | interval = setInterval(function () {
|
47 | logger.info(++logIndex);
|
48 | stress(200);
|
49 | }, 0);
|
50 |
|
51 | logger.info(++logIndex);
|
52 | stress(200);
|
53 |
|
54 | function stress(duration) {
|
55 | var startTime = Date.now();
|
56 |
|
57 | while (Date.now() - startTime < duration) {
|
58 | Math.sqrt(Math.PI);
|
59 | }
|
60 | }
|
61 | },
|
62 | 'should not skip any log lines': function (results) {
|
63 | var testIndex = 0;
|
64 |
|
65 | results.file.forEach(function (log) {
|
66 | if (+log.message !== ++testIndex) {
|
67 | throw new Error('Number skipped');
|
68 | }
|
69 | });
|
70 | }
|
71 | }
|
72 | }).export(module);
|