1
- // This source code is dual-licensed under the Apache License, version
2
- // 2.0, and the Mozilla Public License, version 1.1.
3
- //
4
- // The APL v2.0:
5
- //
6
- //---------------------------------------------------------------------------
7
- // Copyright (C) 2007-2011 VMware, Inc.
8
- //
9
- // Licensed under the Apache License, Version 2.0 (the "License");
10
- // you may not use this file except in compliance with the License.
11
- // You may obtain a copy of the License at
12
- //
13
- // http://www.apache.org/licenses/LICENSE-2.0
14
- //
15
- // Unless required by applicable law or agreed to in writing, software
16
- // distributed under the License is distributed on an "AS IS" BASIS,
17
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
- // See the License for the specific language governing permissions and
19
- // limitations under the License.
20
- //---------------------------------------------------------------------------
21
- //
22
- // The MPL v1.1:
23
- //
24
- //---------------------------------------------------------------------------
25
- // The contents of this file are subject to the Mozilla Public License
26
- // Version 1.1 (the "License"); you may not use this file except in
27
- // compliance with the License. You may obtain a copy of the License
28
- // at http://www.mozilla.org/MPL/
29
- //
30
- // Software distributed under the License is distributed on an "AS IS"
31
- // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
32
- // the License for the specific language governing rights and
33
- // limitations under the License.
34
- //
35
- // The Original Code is RabbitMQ.
36
- //
37
- // The Initial Developer of the Original Code is VMware, Inc.
38
- // Copyright (c) 2007-2011 VMware, Inc. All rights reserved.
39
- //---------------------------------------------------------------------------
40
-
41
- using NUnit . Framework ;
42
-
43
- using System ;
44
- using System . IO ;
45
- using System . Collections ;
46
- using System . Threading ;
47
-
1
+ // This source code is dual-licensed under the Apache License, version
2
+ // 2.0, and the Mozilla Public License, version 1.1.
3
+ //
4
+ // The APL v2.0:
5
+ //
6
+ //---------------------------------------------------------------------------
7
+ // Copyright (C) 2007-2011 VMware, Inc.
8
+ //
9
+ // Licensed under the Apache License, Version 2.0 (the "License");
10
+ // you may not use this file except in compliance with the License.
11
+ // You may obtain a copy of the License at
12
+ //
13
+ // http://www.apache.org/licenses/LICENSE-2.0
14
+ //
15
+ // Unless required by applicable law or agreed to in writing, software
16
+ // distributed under the License is distributed on an "AS IS" BASIS,
17
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ // See the License for the specific language governing permissions and
19
+ // limitations under the License.
20
+ //---------------------------------------------------------------------------
21
+ //
22
+ // The MPL v1.1:
23
+ //
24
+ //---------------------------------------------------------------------------
25
+ // The contents of this file are subject to the Mozilla Public License
26
+ // Version 1.1 (the "License"); you may not use this file except in
27
+ // compliance with the License. You may obtain a copy of the License
28
+ // at http://www.mozilla.org/MPL/
29
+ //
30
+ // Software distributed under the License is distributed on an "AS IS"
31
+ // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
32
+ // the License for the specific language governing rights and
33
+ // limitations under the License.
34
+ //
35
+ // The Original Code is RabbitMQ.
36
+ //
37
+ // The Initial Developer of the Original Code is VMware, Inc.
38
+ // Copyright (c) 2007-2011 VMware, Inc. All rights reserved.
39
+ //---------------------------------------------------------------------------
40
+
41
+ using NUnit . Framework ;
42
+
43
+ using System ;
44
+ using System . IO ;
45
+ using System . Collections ;
46
+ using System . Threading ;
47
+
48
48
using RabbitMQ . Util ;
49
49
50
50
namespace RabbitMQ . Client . Unit
51
51
{
52
52
[ TestFixture ]
53
- public class TestBlockingCell
53
+ public class TestBlockingCell : TimingFixture
54
54
{
55
55
public class DelayedSetter
56
56
{
@@ -101,8 +101,8 @@ public void TestTimeoutShort()
101
101
102
102
ResetTimer ( ) ;
103
103
object v ;
104
- bool r = k . GetValue ( 250 , out v ) ;
105
- Assert . Greater ( 50 , ElapsedMs ( ) ) ;
104
+ bool r = k . GetValue ( TimingInterval , out v ) ;
105
+ Assert . Greater ( SafetyMargin , ElapsedMs ( ) ) ;
106
106
Assert . IsTrue ( r ) ;
107
107
Assert . AreEqual ( 123 , v ) ;
108
108
}
@@ -114,8 +114,8 @@ public void TestTimeoutLong()
114
114
115
115
ResetTimer ( ) ;
116
116
object v ;
117
- bool r = k . GetValue ( 250 , out v ) ;
118
- Assert . Greater ( ElapsedMs ( ) , 200 ) ;
117
+ bool r = k . GetValue ( TimingInterval , out v ) ;
118
+ Assert . Less ( TimingInterval - SafetyMargin , ElapsedMs ( ) ) ;
119
119
Assert . IsTrue ( ! r ) ;
120
120
Assert . AreEqual ( null , v ) ;
121
121
}
@@ -128,7 +128,7 @@ public void TestTimeoutNegative()
128
128
ResetTimer ( ) ;
129
129
object v ;
130
130
bool r = k . GetValue ( - 10000 , out v ) ;
131
- Assert . Greater ( 50 , ElapsedMs ( ) ) ;
131
+ Assert . Greater ( SafetyMargin , ElapsedMs ( ) ) ;
132
132
Assert . IsTrue ( ! r ) ;
133
133
Assert . AreEqual ( null , v ) ;
134
134
}
@@ -137,12 +137,12 @@ public void TestTimeoutNegative()
137
137
public void TestTimeoutInfinite ( )
138
138
{
139
139
BlockingCell k = new BlockingCell ( ) ;
140
- SetAfter ( 250 , k , 123 ) ;
140
+ SetAfter ( TimingInterval , k , 123 ) ;
141
141
142
142
ResetTimer ( ) ;
143
143
object v ;
144
144
bool r = k . GetValue ( Timeout . Infinite , out v ) ;
145
- Assert . Greater ( ElapsedMs ( ) , 200 ) ;
145
+ Assert . Less ( TimingInterval - SafetyMargin , ElapsedMs ( ) ) ;
146
146
Assert . IsTrue ( r ) ;
147
147
Assert . AreEqual ( 123 , v ) ;
148
148
}
@@ -151,12 +151,12 @@ public void TestTimeoutInfinite()
151
151
public void TestBgShort ( )
152
152
{
153
153
BlockingCell k = new BlockingCell ( ) ;
154
- SetAfter ( 50 , k , 123 ) ;
154
+ SetAfter ( TimingInterval , k , 123 ) ;
155
155
156
156
ResetTimer ( ) ;
157
157
object v ;
158
- bool r = k . GetValue ( 100 , out v ) ;
159
- Assert . Greater ( ElapsedMs ( ) , 40 ) ;
158
+ bool r = k . GetValue ( TimingInterval * 2 , out v ) ;
159
+ Assert . Less ( TimingInterval - SafetyMargin , ElapsedMs ( ) ) ;
160
160
Assert . IsTrue ( r ) ;
161
161
Assert . AreEqual ( 123 , v ) ;
162
162
}
@@ -165,12 +165,12 @@ public void TestBgShort()
165
165
public void TestBgLong ( )
166
166
{
167
167
BlockingCell k = new BlockingCell ( ) ;
168
- SetAfter ( 150 , k , 123 ) ;
168
+ SetAfter ( TimingInterval * 2 , k , 123 ) ;
169
169
170
170
ResetTimer ( ) ;
171
171
object v ;
172
- bool r = k . GetValue ( 100 , out v ) ;
173
- Assert . Greater ( 110 , ElapsedMs ( ) ) ;
172
+ bool r = k . GetValue ( TimingInterval , out v ) ;
173
+ Assert . Greater ( TimingInterval + SafetyMargin , ElapsedMs ( ) ) ;
174
174
Assert . IsTrue ( ! r ) ;
175
175
Assert . AreEqual ( null , v ) ;
176
176
}
0 commit comments