@@ -139,6 +139,7 @@ func TestFailApplication(t *testing.T) {
139
139
rt .time ++
140
140
}
141
141
events .SetRecorder (mr )
142
+ defer events .SetRecorder (events .NewMockedRecorder ())
142
143
resources := make (map [v1.ResourceName ]resource.Quantity )
143
144
containers := make ([]v1.Container , 0 )
144
145
containers = append (containers , v1.Container {
@@ -200,8 +201,6 @@ func TestFailApplication(t *testing.T) {
200
201
assert .NilError (t , err )
201
202
assertAppState (t , app2 , ApplicationStates ().Failed , 3 * time .Second )
202
203
assert .Equal (t , rt .time , int64 (0 ))
203
- // Test over, set Recorder back fake type
204
- events .SetRecorder (k8sEvents .NewFakeRecorder (1024 ))
205
204
}
206
205
207
206
func TestSetUnallocatedPodsToFailedWhenFailApplication (t * testing.T ) {
@@ -228,6 +227,7 @@ func TestSetUnallocatedPodsToFailedWhenFailApplication(t *testing.T) {
228
227
// set Recorder to mocked type
229
228
mr := events .NewMockedRecorder ()
230
229
events .SetRecorder (mr )
230
+ defer events .SetRecorder (events .NewMockedRecorder ())
231
231
resources := make (map [v1.ResourceName ]resource.Quantity )
232
232
containers := make ([]v1.Container , 0 )
233
233
containers = append (containers , v1.Container {
@@ -306,8 +306,6 @@ func TestSetUnallocatedPodsToFailedWhenFailApplication(t *testing.T) {
306
306
assert .NilError (t , err )
307
307
assert .Equal (t , newPod3 .Status .Phase , v1 .PodFailed , 3 * time .Second )
308
308
assert .Equal (t , newPod3 .Status .Reason , constants .ApplicationInsufficientResourcesFailure , 3 * time .Second )
309
- // Test over, set Recorder back fake type
310
- events .SetRecorder (k8sEvents .NewFakeRecorder (1024 ))
311
309
}
312
310
313
311
func TestSetUnallocatedPodsToFailedWhenRejectApplication (t * testing.T ) {
@@ -334,6 +332,7 @@ func TestSetUnallocatedPodsToFailedWhenRejectApplication(t *testing.T) {
334
332
// set Recorder to mocked type
335
333
mr := events .NewMockedRecorder ()
336
334
events .SetRecorder (mr )
335
+ defer events .SetRecorder (events .NewMockedRecorder ())
337
336
resources := make (map [v1.ResourceName ]resource.Quantity )
338
337
containers := make ([]v1.Container , 0 )
339
338
containers = append (containers , v1.Container {
@@ -404,8 +403,6 @@ func TestSetUnallocatedPodsToFailedWhenRejectApplication(t *testing.T) {
404
403
assert .NilError (t , err )
405
404
assert .Equal (t , newPod2 .Status .Phase , v1 .PodFailed , 3 * time .Second )
406
405
assert .Equal (t , newPod2 .Status .Reason , constants .ApplicationRejectedFailure , 3 * time .Second )
407
- // Test over, set Recorder back fake type
408
- events .SetRecorder (k8sEvents .NewFakeRecorder (1024 ))
409
406
}
410
407
411
408
func TestReleaseAppAllocation (t * testing.T ) {
@@ -1110,10 +1107,9 @@ func TestGetPlaceholderTasks(t *testing.T) {
1110
1107
1111
1108
func TestPlaceholderTimeoutEvents (t * testing.T ) {
1112
1109
context := initContextForTest ()
1113
- recorder , ok := events .GetRecorder ().(* k8sEvents.FakeRecorder )
1114
- if ! ok {
1115
- t .Fatal ("the EventRecorder is expected to be of type FakeRecorder" )
1116
- }
1110
+ recorder := k8sEvents .NewFakeRecorder (1024 )
1111
+ events .SetRecorder (recorder )
1112
+ defer events .SetRecorder (events .NewMockedRecorder ())
1117
1113
1118
1114
pod1 := v1.Pod {
1119
1115
TypeMeta : apis.TypeMeta {
@@ -1213,10 +1209,9 @@ func TestApplication_onReservationStateChange(t *testing.T) {
1213
1209
dispatcher .Start ()
1214
1210
defer dispatcher .Stop ()
1215
1211
1216
- recorder , ok := events .GetRecorder ().(* k8sEvents.FakeRecorder )
1217
- if ! ok {
1218
- t .Fatal ("the EventRecorder is expected to be of type FakeRecorder" )
1219
- }
1212
+ recorder := k8sEvents .NewFakeRecorder (1024 )
1213
+ events .SetRecorder (recorder )
1214
+ defer events .SetRecorder (events .NewMockedRecorder ())
1220
1215
1221
1216
app := NewApplication (appID , "root.a" , "testuser" , testGroups , map [string ]string {}, newMockSchedulerAPI ())
1222
1217
context .addApplicationToContext (app )
0 commit comments