@@ -8,7 +8,7 @@ var expect = require('chai').expect,
8
8
const test = new ReplSetFixture ( ) ;
9
9
describe ( 'Sessions (ReplSet)' , function ( ) {
10
10
afterEach ( ( ) => mock . cleanup ( ) ) ;
11
- beforeEach ( ( ) => test . setup ( ) ) ;
11
+ beforeEach ( ( ) => test . setup ( { ismaster : mock . DEFAULT_ISMASTER_36 } ) ) ;
12
12
13
13
it ( 'should track the highest `clusterTime` seen in a replica set' , {
14
14
metadata : { requires : { topology : 'single' } } ,
@@ -31,14 +31,10 @@ describe('Sessions (ReplSet)', function() {
31
31
}
32
32
) ;
33
33
34
- let serverCount = 0 ;
35
- replset . on ( 'joined' , ( ) => {
36
- serverCount ++ ;
37
- if ( serverCount === 3 ) {
38
- expect ( replset . clusterTime ) . to . eql ( futureClusterTime ) ;
39
- replset . destroy ( ) ;
40
- done ( ) ;
41
- }
34
+ replset . on ( 'all' , ( ) => {
35
+ expect ( replset . clusterTime ) . to . eql ( futureClusterTime ) ;
36
+ replset . destroy ( ) ;
37
+ done ( ) ;
42
38
} ) ;
43
39
44
40
replset . on ( 'error' , done ) ;
@@ -67,19 +63,15 @@ describe('Sessions (ReplSet)', function() {
67
63
}
68
64
) ;
69
65
70
- let serverCount = 0 ;
71
- replset . on ( 'joined' , ( ) => {
72
- serverCount ++ ;
73
- if ( serverCount === 3 ) {
74
- expect ( replset . clusterTime ) . to . eql ( futureClusterTime ) ;
75
- const servers = replset . s . replicaSetState . secondaries
76
- . concat ( replset . s . replicaSetState . arbiters )
77
- . concat ( [ replset . s . replicaSetState . primary ] ) ;
78
- servers . forEach ( server => expect ( server . clusterTime ) . to . eql ( futureClusterTime ) ) ;
66
+ replset . on ( 'all' , ( ) => {
67
+ expect ( replset . clusterTime ) . to . eql ( futureClusterTime ) ;
68
+ const servers = replset . s . replicaSetState . secondaries
69
+ . concat ( replset . s . replicaSetState . arbiters )
70
+ . concat ( [ replset . s . replicaSetState . primary ] ) ;
71
+ servers . forEach ( server => expect ( server . clusterTime ) . to . eql ( futureClusterTime ) ) ;
79
72
80
- replset . destroy ( ) ;
81
- done ( ) ;
82
- }
73
+ replset . destroy ( ) ;
74
+ done ( ) ;
83
75
} ) ;
84
76
85
77
replset . on ( 'error' , done ) ;
@@ -90,6 +82,8 @@ describe('Sessions (ReplSet)', function() {
90
82
it ( 'should set `logicalSessionTimeoutMinutes` to `null` if any incoming server is `null`' , {
91
83
metadata : { requires : { topology : 'single' } } ,
92
84
test : function ( done ) {
85
+ test . firstSecondaryStates [ 0 ] . logicalSessionTimeoutMinutes = null ;
86
+
93
87
const replset = new ReplSet (
94
88
[ test . primaryServer . address ( ) , test . firstSecondaryServer . address ( ) ] ,
95
89
{
@@ -102,7 +96,7 @@ describe('Sessions (ReplSet)', function() {
102
96
) ;
103
97
104
98
replset . on ( 'error' , done ) ;
105
- replset . once ( 'connect ' , ( ) => {
99
+ replset . once ( 'all ' , ( ) => {
106
100
expect ( replset . logicalSessionTimeoutMinutes ) . to . equal ( null ) ;
107
101
replset . destroy ( ) ;
108
102
done ( ) ;
@@ -132,20 +126,45 @@ describe('Sessions (ReplSet)', function() {
132
126
}
133
127
) ;
134
128
135
- let joinCount = 0 ;
136
- replset . on ( 'joined' , ( ) => {
137
- joinCount ++ ;
138
-
139
- if ( joinCount === 3 ) {
140
- expect ( replset . logicalSessionTimeoutMinutes ) . to . equal ( 1 ) ;
141
- replset . destroy ( ) ;
142
- done ( ) ;
143
- }
129
+ replset . on ( 'all' , ( ) => {
130
+ expect ( replset . logicalSessionTimeoutMinutes ) . to . equal ( 1 ) ;
131
+ replset . destroy ( ) ;
132
+ done ( ) ;
144
133
} ) ;
145
134
146
135
replset . on ( 'error' , done ) ;
147
136
replset . connect ( ) ;
148
137
}
149
138
}
150
139
) ;
140
+
141
+ it ( 'should exclude arbiters when tracking `logicalSessionTimeoutMinutes`' , {
142
+ metadata : { requires : { topology : 'single' } } ,
143
+ test : function ( done ) {
144
+ test . arbiterServer . setMessageHandler ( req => {
145
+ const doc = req . document ;
146
+ if ( doc . ismaster ) {
147
+ req . reply ( Object . assign ( { } , test . arbiterStates [ 0 ] , { logicalSessionTimeoutMinutes : 2 } ) ) ;
148
+ }
149
+ } ) ;
150
+
151
+ const replset = new ReplSet ( test . servers . map ( s => s . address ( ) ) , {
152
+ setName : 'rs' ,
153
+ connectionTimeout : 3000 ,
154
+ socketTimeout : 0 ,
155
+ haInterval : 100 ,
156
+ size : 1
157
+ } ) ;
158
+
159
+ replset . on ( 'joined' , type => {
160
+ if ( type === 'arbiter' ) {
161
+ expect ( replset . logicalSessionTimeoutMinutes ) . to . equal ( 10 ) ;
162
+ done ( ) ;
163
+ }
164
+ } ) ;
165
+
166
+ replset . on ( 'error' , done ) ;
167
+ replset . connect ( ) ;
168
+ }
169
+ } ) ;
151
170
} ) ;
0 commit comments