@@ -36,17 +36,30 @@ if (cluster.isMaster) {
36
36
test ( 'cluster master' , ( batch ) => {
37
37
batch . test ( 'events should be logged' , ( t ) => {
38
38
t . equal ( logEvents . length , 3 ) ;
39
+
39
40
t . equal ( logEvents [ 0 ] . categoryName , 'master' ) ;
40
41
t . equal ( logEvents [ 0 ] . pid , masterPid ) ;
42
+
41
43
t . equal ( logEvents [ 1 ] . categoryName , 'worker' ) ;
42
44
t . equal ( logEvents [ 1 ] . pid , workerPid ) ;
45
+ // serialising errors with stacks intact
43
46
t . type ( logEvents [ 1 ] . data [ 1 ] , 'Error' ) ;
44
47
t . contains ( logEvents [ 1 ] . data [ 1 ] . stack , 'Error: oh dear' ) ;
48
+ // serialising circular references in objects
45
49
t . type ( logEvents [ 1 ] . data [ 2 ] , 'object' ) ;
46
50
t . type ( logEvents [ 1 ] . data [ 2 ] . me , 'object' ) ;
51
+ // serialising errors with custom properties
52
+ t . type ( logEvents [ 1 ] . data [ 3 ] , 'Error' ) ;
53
+ t . contains ( logEvents [ 1 ] . data [ 3 ] . stack , 'Error: wtf' ) ;
54
+ t . equal ( logEvents [ 1 ] . data [ 3 ] . alert , 'chartreuse' ) ;
55
+ // serialising things that are not errors, but look a bit like them
56
+ t . type ( logEvents [ 1 ] . data [ 4 ] , 'object' ) ;
57
+ t . equal ( logEvents [ 1 ] . data [ 4 ] . stack , 'this is not a stack trace' ) ;
58
+
47
59
t . equal ( logEvents [ 2 ] . categoryName , 'log4js' ) ;
48
60
t . equal ( logEvents [ 2 ] . level . toString ( ) , 'ERROR' ) ;
49
61
t . equal ( logEvents [ 2 ] . data [ 0 ] , 'Unable to parse log:' ) ;
62
+
50
63
t . end ( ) ;
51
64
} ) ;
52
65
@@ -63,9 +76,15 @@ if (cluster.isMaster) {
63
76
} ) ;
64
77
} else {
65
78
const workerLogger = log4js . getLogger ( 'worker' ) ;
79
+ // test for serialising circular references
66
80
const circle = { } ;
67
81
circle . me = circle ;
68
- workerLogger . info ( 'this is worker' , new Error ( 'oh dear' ) , circle ) ;
82
+ // test for serialising errors with their own properties
83
+ const someError = new Error ( 'wtf' ) ;
84
+ someError . alert = 'chartreuse' ;
85
+ // test for serialising things that look like errors but aren't.
86
+ const notAnError = { stack : 'this is not a stack trace' } ;
87
+ workerLogger . info ( 'this is worker' , new Error ( 'oh dear' ) , circle , someError , notAnError ) ;
69
88
// can't run the test in the worker, things get weird
70
89
process . send ( {
71
90
type : '::testing' ,
0 commit comments