@@ -227,6 +227,18 @@ func Test_Run_Positive_OneDesiredVolumeAttachThenDetachWithMountedVolume(t *test
227
227
registerMetrics .Do (func () {
228
228
legacyregistry .MustRegister (metrics .ForceDetachMetricCounter )
229
229
})
230
+
231
+ // NOTE: This value is being pulled from a global variable, so it won't necessarily be 0 at the start of the test
232
+ initialForceDetachCountTimeout , err := metricstestutil .GetCounterMetricValue (metrics .ForceDetachMetricCounter .WithLabelValues (metrics .ForceDetachReasonTimeout ))
233
+ if err != nil {
234
+ t .Errorf ("Error getting initialForceDetachCountTimeout" )
235
+ }
236
+
237
+ initialForceDetachCountOutOfService , err := metricstestutil .GetCounterMetricValue (metrics .ForceDetachMetricCounter .WithLabelValues (metrics .ForceDetachReasonOutOfService ))
238
+ if err != nil {
239
+ t .Errorf ("Error getting initialForceDetachCountOutOfService" )
240
+ }
241
+
230
242
// Arrange
231
243
volumePluginMgr , fakePlugin := volumetesting .GetTestVolumePluginMgr (t )
232
244
dsw := cache .NewDesiredStateOfWorld (volumePluginMgr )
@@ -295,7 +307,9 @@ func Test_Run_Positive_OneDesiredVolumeAttachThenDetachWithMountedVolume(t *test
295
307
waitForDetachCallCount (t , 1 /* expectedDetachCallCount */ , fakePlugin )
296
308
297
309
// Force detach metric due to timeout
298
- testForceDetachMetric (t , 1 , metrics .ForceDetachReasonTimeout )
310
+ testForceDetachMetric (t , int (initialForceDetachCountTimeout )+ 1 , metrics .ForceDetachReasonTimeout )
311
+ // We shouldn't see any additional force detaches, so only consider the initial count
312
+ testForceDetachMetric (t , int (initialForceDetachCountOutOfService ), metrics .ForceDetachReasonOutOfService )
299
313
}
300
314
301
315
// Populates desiredStateOfWorld cache with one node/volume/pod tuple.
@@ -852,6 +866,18 @@ func Test_Run_OneVolumeDetachOnOutOfServiceTaintedNode(t *testing.T) {
852
866
registerMetrics .Do (func () {
853
867
legacyregistry .MustRegister (metrics .ForceDetachMetricCounter )
854
868
})
869
+
870
+ // NOTE: This value is being pulled from a global variable, so it won't necessarily be 0 at the start of the test
871
+ initialForceDetachCountOutOfService , err := metricstestutil .GetCounterMetricValue (metrics .ForceDetachMetricCounter .WithLabelValues (metrics .ForceDetachReasonOutOfService ))
872
+ if err != nil {
873
+ t .Errorf ("Error getting initialForceDetachCountOutOfService" )
874
+ }
875
+
876
+ initialForceDetachCountTimeout , err := metricstestutil .GetCounterMetricValue (metrics .ForceDetachMetricCounter .WithLabelValues (metrics .ForceDetachReasonTimeout ))
877
+ if err != nil {
878
+ t .Errorf ("Error getting initialForceDetachCountTimeout" )
879
+ }
880
+
855
881
// Arrange
856
882
volumePluginMgr , fakePlugin := volumetesting .GetTestVolumePluginMgr (t )
857
883
dsw := cache .NewDesiredStateOfWorld (volumePluginMgr )
@@ -922,7 +948,9 @@ func Test_Run_OneVolumeDetachOnOutOfServiceTaintedNode(t *testing.T) {
922
948
waitForDetachCallCount (t , 1 /* expectedDetachCallCount */ , fakePlugin )
923
949
924
950
// Force detach metric due to out-of-service taint
925
- testForceDetachMetric (t , 1 , metrics .ForceDetachReasonOutOfService )
951
+ testForceDetachMetric (t , int (initialForceDetachCountOutOfService )+ 1 , metrics .ForceDetachReasonOutOfService )
952
+ // We shouldn't see any additional force detaches, so only consider the initial count
953
+ testForceDetachMetric (t , int (initialForceDetachCountTimeout ), metrics .ForceDetachReasonTimeout )
926
954
}
927
955
928
956
// Populates desiredStateOfWorld cache with one node/volume/pod tuple.
@@ -1119,10 +1147,14 @@ func Test_Run_OneVolumeDetachOnUnhealthyNodeWithForceDetachOnUnmountDisabled(t *
1119
1147
legacyregistry .MustRegister (metrics .ForceDetachMetricCounter )
1120
1148
})
1121
1149
// NOTE: This value is being pulled from a global variable, so it won't necessarily be 0 at the start of the test
1122
- // For example, if Test_Run_OneVolumeDetachOnOutOfServiceTaintedNode runs before this test, then it will be 1
1123
- initialForceDetachCount , err := metricstestutil .GetCounterMetricValue (metrics .ForceDetachMetricCounter .WithLabelValues (metrics .ForceDetachReasonOutOfService ))
1150
+ initialForceDetachCountOutOfService , err := metricstestutil .GetCounterMetricValue (metrics .ForceDetachMetricCounter .WithLabelValues (metrics .ForceDetachReasonOutOfService ))
1124
1151
if err != nil {
1125
- t .Errorf ("Error getting initialForceDetachCount" )
1152
+ t .Errorf ("Error getting initialForceDetachCountOutOfService" )
1153
+ }
1154
+
1155
+ initialForceDetachCountTimeout , err := metricstestutil .GetCounterMetricValue (metrics .ForceDetachMetricCounter .WithLabelValues (metrics .ForceDetachReasonTimeout ))
1156
+ if err != nil {
1157
+ t .Errorf ("Error getting initialForceDetachCountTimeout" )
1126
1158
}
1127
1159
1128
1160
// Arrange
@@ -1219,7 +1251,8 @@ func Test_Run_OneVolumeDetachOnUnhealthyNodeWithForceDetachOnUnmountDisabled(t *
1219
1251
1220
1252
// Force detach metric due to out-of-service taint
1221
1253
// We shouldn't see any additional force detaches, so only consider the initial count
1222
- testForceDetachMetric (t , int (initialForceDetachCount ), metrics .ForceDetachReasonOutOfService )
1254
+ testForceDetachMetric (t , int (initialForceDetachCountOutOfService ), metrics .ForceDetachReasonOutOfService )
1255
+ testForceDetachMetric (t , int (initialForceDetachCountTimeout ), metrics .ForceDetachReasonTimeout )
1223
1256
1224
1257
// Act
1225
1258
// Taint the node
@@ -1238,7 +1271,9 @@ func Test_Run_OneVolumeDetachOnUnhealthyNodeWithForceDetachOnUnmountDisabled(t *
1238
1271
1239
1272
// Force detach metric due to out-of-service taint
1240
1273
// We should see one more force detach, so consider the initial count + 1
1241
- testForceDetachMetric (t , int (initialForceDetachCount )+ 1 , metrics .ForceDetachReasonOutOfService )
1274
+ testForceDetachMetric (t , int (initialForceDetachCountOutOfService )+ 1 , metrics .ForceDetachReasonOutOfService )
1275
+ // We shouldn't see any additional force detaches, so only consider the initial count
1276
+ testForceDetachMetric (t , int (initialForceDetachCountTimeout ), metrics .ForceDetachReasonTimeout )
1242
1277
}
1243
1278
1244
1279
func Test_ReportMultiAttachError (t * testing.T ) {
0 commit comments