17
17
18
18
import * as assert from 'assert' ;
19
19
import * as grpc from '../src' ;
20
- import { TestClient , TestServer } from " ./common" ;
20
+ import { TestClient , TestServer } from ' ./common' ;
21
21
22
22
describe ( 'Channel idle timer' , ( ) => {
23
23
let server : TestServer ;
@@ -31,65 +31,100 @@ describe('Channel idle timer', () => {
31
31
client . close ( ) ;
32
32
client = null ;
33
33
}
34
- } )
34
+ } ) ;
35
35
after ( ( ) => {
36
36
server . shutdown ( ) ;
37
37
} ) ;
38
- it ( 'Should go idle after the specified time after a request ends' , function ( done ) {
38
+ it ( 'Should go idle after the specified time after a request ends' , function ( done ) {
39
39
this . timeout ( 5000 ) ;
40
- client = TestClient . createFromServer ( server , { 'grpc.client_idle_timeout_ms' : 1000 } ) ;
40
+ client = TestClient . createFromServer ( server , {
41
+ 'grpc.client_idle_timeout_ms' : 1000 ,
42
+ } ) ;
41
43
client . sendRequest ( error => {
42
44
assert . ifError ( error ) ;
43
- assert . strictEqual ( client ! . getChannelState ( ) , grpc . connectivityState . READY ) ;
45
+ assert . strictEqual (
46
+ client ! . getChannelState ( ) ,
47
+ grpc . connectivityState . READY
48
+ ) ;
44
49
setTimeout ( ( ) => {
45
- assert . strictEqual ( client ! . getChannelState ( ) , grpc . connectivityState . IDLE ) ;
50
+ assert . strictEqual (
51
+ client ! . getChannelState ( ) ,
52
+ grpc . connectivityState . IDLE
53
+ ) ;
46
54
done ( ) ;
47
55
} , 1100 ) ;
48
56
} ) ;
49
57
} ) ;
50
- it ( 'Should be able to make a request after going idle' , function ( done ) {
58
+ it ( 'Should be able to make a request after going idle' , function ( done ) {
51
59
this . timeout ( 5000 ) ;
52
- client = TestClient . createFromServer ( server , { 'grpc.client_idle_timeout_ms' : 1000 } ) ;
60
+ client = TestClient . createFromServer ( server , {
61
+ 'grpc.client_idle_timeout_ms' : 1000 ,
62
+ } ) ;
53
63
client . sendRequest ( error => {
54
64
assert . ifError ( error ) ;
55
- assert . strictEqual ( client ! . getChannelState ( ) , grpc . connectivityState . READY ) ;
65
+ assert . strictEqual (
66
+ client ! . getChannelState ( ) ,
67
+ grpc . connectivityState . READY
68
+ ) ;
56
69
setTimeout ( ( ) => {
57
- assert . strictEqual ( client ! . getChannelState ( ) , grpc . connectivityState . IDLE ) ;
70
+ assert . strictEqual (
71
+ client ! . getChannelState ( ) ,
72
+ grpc . connectivityState . IDLE
73
+ ) ;
58
74
client ! . sendRequest ( error => {
59
75
assert . ifError ( error ) ;
60
76
done ( ) ;
61
77
} ) ;
62
78
} , 1100 ) ;
63
79
} ) ;
64
80
} ) ;
65
- it ( 'Should go idle after the specified time after waitForReady ends' , function ( done ) {
81
+ it ( 'Should go idle after the specified time after waitForReady ends' , function ( done ) {
66
82
this . timeout ( 5000 ) ;
67
- client = TestClient . createFromServer ( server , { 'grpc.client_idle_timeout_ms' : 1000 } ) ;
83
+ client = TestClient . createFromServer ( server , {
84
+ 'grpc.client_idle_timeout_ms' : 1000 ,
85
+ } ) ;
68
86
const deadline = new Date ( ) ;
69
87
deadline . setSeconds ( deadline . getSeconds ( ) + 3 ) ;
70
88
client . waitForReady ( deadline , error => {
71
89
assert . ifError ( error ) ;
72
- assert . strictEqual ( client ! . getChannelState ( ) , grpc . connectivityState . READY ) ;
90
+ assert . strictEqual (
91
+ client ! . getChannelState ( ) ,
92
+ grpc . connectivityState . READY
93
+ ) ;
73
94
setTimeout ( ( ) => {
74
- assert . strictEqual ( client ! . getChannelState ( ) , grpc . connectivityState . IDLE ) ;
95
+ assert . strictEqual (
96
+ client ! . getChannelState ( ) ,
97
+ grpc . connectivityState . IDLE
98
+ ) ;
75
99
done ( ) ;
76
100
} , 1100 ) ;
77
101
} ) ;
78
102
} ) ;
79
- it ( 'Should ensure that the timeout is at least 1 second' , function ( done ) {
80
- client = TestClient . createFromServer ( server , { 'grpc.client_idle_timeout_ms' : 50 } ) ;
103
+ it ( 'Should ensure that the timeout is at least 1 second' , function ( done ) {
104
+ client = TestClient . createFromServer ( server , {
105
+ 'grpc.client_idle_timeout_ms' : 50 ,
106
+ } ) ;
81
107
client . sendRequest ( error => {
82
108
assert . ifError ( error ) ;
83
- assert . strictEqual ( client ! . getChannelState ( ) , grpc . connectivityState . READY ) ;
109
+ assert . strictEqual (
110
+ client ! . getChannelState ( ) ,
111
+ grpc . connectivityState . READY
112
+ ) ;
84
113
setTimeout ( ( ) => {
85
114
// Should still be ready after 100ms
86
- assert . strictEqual ( client ! . getChannelState ( ) , grpc . connectivityState . READY ) ;
115
+ assert . strictEqual (
116
+ client ! . getChannelState ( ) ,
117
+ grpc . connectivityState . READY
118
+ ) ;
87
119
setTimeout ( ( ) => {
88
120
// Should go IDLE after another second
89
- assert . strictEqual ( client ! . getChannelState ( ) , grpc . connectivityState . IDLE ) ;
121
+ assert . strictEqual (
122
+ client ! . getChannelState ( ) ,
123
+ grpc . connectivityState . IDLE
124
+ ) ;
90
125
done ( ) ;
91
126
} , 1000 ) ;
92
127
} , 100 ) ;
93
128
} ) ;
94
- } )
95
- } ) ;
129
+ } ) ;
130
+ } ) ;
0 commit comments