1
+ // Flags: --abort_on_uncaught_exception
2
+
1
3
var common = require ( '../common' ) ;
2
4
var assert = require ( 'assert' ) ;
3
- var spawn = require ( 'child_process' ) . spawn ;
5
+ var domain = require ( 'domain' ) ;
4
6
5
7
var tests = [
6
8
nextTick ,
7
9
timer ,
8
10
timerPlusNextTick ,
11
+ netServer ,
9
12
firstRun ,
10
- netServer
11
- ]
13
+ ] ;
12
14
13
- tests . forEach ( function ( test ) {
14
- console . log ( test . name ) ;
15
- var child = spawn ( process . execPath , [
16
- '--abort-on-uncaught-exception' ,
17
- '-e' ,
18
- '(' + test + ')()' ,
19
- common . PORT
20
- ] ) ;
21
- child . stderr . pipe ( process . stderr ) ;
22
- child . stdout . pipe ( process . stdout ) ;
23
- child . on ( 'exit' , function ( code ) {
24
- assert . strictEqual ( code , 0 ) ;
25
- } ) ;
15
+ var errors = 0 ;
16
+
17
+ process . on ( 'exit' , function ( ) {
18
+ assert . equal ( errors , tests . length ) ;
26
19
} ) ;
27
20
21
+ tests . forEach ( function ( test ) { test ( ) ; } )
22
+
28
23
function nextTick ( ) {
29
- var domain = require ( 'domain' ) ;
30
24
var d = domain . create ( ) ;
31
25
32
- d . on ( 'error' , function ( err ) {
33
- console . log ( 'ok' ) ;
34
- process . exit ( 0 ) ;
26
+ d . once ( 'error' , function ( err ) {
27
+ errors += 1 ;
35
28
} ) ;
36
29
d . run ( function ( ) {
37
30
process . nextTick ( function ( ) {
@@ -41,12 +34,10 @@ function nextTick() {
41
34
}
42
35
43
36
function timer ( ) {
44
- var domain = require ( 'domain' ) ;
45
37
var d = domain . create ( ) ;
46
38
47
39
d . on ( 'error' , function ( err ) {
48
- console . log ( 'ok' ) ;
49
- process . exit ( 0 ) ;
40
+ errors += 1 ;
50
41
} ) ;
51
42
d . run ( function ( ) {
52
43
setTimeout ( function ( ) {
@@ -56,12 +47,10 @@ function timer() {
56
47
}
57
48
58
49
function timerPlusNextTick ( ) {
59
- var domain = require ( 'domain' ) ;
60
50
var d = domain . create ( ) ;
61
51
62
52
d . on ( 'error' , function ( err ) {
63
- console . log ( 'ok' ) ;
64
- process . exit ( 0 ) ;
53
+ errors += 1 ;
65
54
} ) ;
66
55
d . run ( function ( ) {
67
56
setTimeout ( function ( ) {
@@ -73,37 +62,34 @@ function timerPlusNextTick() {
73
62
}
74
63
75
64
function firstRun ( ) {
76
- var domain = require ( 'domain' ) ;
77
65
var d = domain . create ( ) ;
78
66
79
67
d . on ( 'error' , function ( err ) {
80
- console . log ( 'ok' ) ;
81
- process . exit ( 0 ) ;
68
+ errors += 1 ;
82
69
} ) ;
83
70
d . run ( function ( ) {
84
71
throw new Error ( 'exceptional!' ) ;
85
72
} ) ;
86
73
}
87
74
88
75
function netServer ( ) {
89
- var domain = require ( 'domain' ) ;
90
76
var net = require ( 'net' ) ;
91
77
var d = domain . create ( ) ;
92
78
93
79
d . on ( 'error' , function ( err ) {
94
- console . log ( 'ok' ) ;
95
- process . exit ( 0 ) ;
80
+ errors += 1 ;
96
81
} ) ;
97
82
d . run ( function ( ) {
98
83
var server = net . createServer ( function ( conn ) {
99
84
conn . pipe ( conn ) ;
100
85
} ) ;
101
- server . listen ( Number ( process . argv [ 1 ] ) , '0.0.0.0' , function ( ) {
102
- var conn = net . connect ( Number ( process . argv [ 1 ] ) , '0.0.0.0' )
86
+ server . listen ( common . PORT , '0.0.0.0' , function ( ) {
87
+ var conn = net . connect ( common . PORT , '0.0.0.0' )
103
88
conn . once ( 'data' , function ( ) {
104
89
throw new Error ( 'ok' ) ;
105
90
} )
106
91
conn . end ( 'ok' ) ;
92
+ server . close ( ) ;
107
93
} ) ;
108
94
} ) ;
109
95
}
0 commit comments