@@ -984,6 +984,17 @@ func TestClient_CallAllExtensions(t *testing.T) {
984
984
},
985
985
}
986
986
987
+ secondBlockingConfig := extensionConfig .DeepCopy ()
988
+ secondBlockingConfig .Status .Handlers [0 ].Priority = 2
989
+ secondBlockingConfig .Status .Handlers [1 ].Priority = 1
990
+ secondBlockingConfig .Status .Handlers [1 ].Serial = true
991
+ secondBlockingConfig .Status .Handlers [0 ].RequestHook .Hook = "RetryableFakeHook"
992
+ secondBlockingConfig .Status .Handlers [1 ].RequestHook .Hook = "RetryableFakeHook"
993
+ secondBlockingConfig .Status .Handlers [2 ].RequestHook .Hook = "RetryableFakeHook"
994
+
995
+ secondBlockingWithPriorityConfig := secondBlockingConfig .DeepCopy ()
996
+ secondBlockingWithPriorityConfig .Status .Handlers [1 ].Priority = 3
997
+
987
998
type args struct {
988
999
hook runtimecatalog.Hook
989
1000
request runtimehooksv1.RequestObject
@@ -1072,6 +1083,55 @@ func TestClient_CallAllExtensions(t *testing.T) {
1072
1083
},
1073
1084
wantErr : true ,
1074
1085
},
1086
+ {
1087
+ name : "should succeed and wait on previous blocking responses for serial handler" ,
1088
+ registeredExtensionConfigs : []runtimev1.ExtensionConfig {* secondBlockingConfig },
1089
+ testServer : testServerConfig {
1090
+ start : true ,
1091
+ responses : map [string ]testServerResponse {
1092
+ "/test.runtime.cluster.x-k8s.io/v1alpha1/retryablefakehook/first-extension.*" : retryResponse (runtimehooksv1 .ResponseStatusSuccess , 1 ),
1093
+ // second and third extension has no handler.
1094
+ },
1095
+ },
1096
+ args : args {
1097
+ hook : fakev1alpha1 .RetryableFakeHook ,
1098
+ request : & fakev1alpha1.RetryableFakeRequest {},
1099
+ response : & fakev1alpha1.RetryableFakeResponse {},
1100
+ },
1101
+ },
1102
+ {
1103
+ name : "should succeed and wait on blocking serial handler" ,
1104
+ registeredExtensionConfigs : []runtimev1.ExtensionConfig {* secondBlockingConfig },
1105
+ testServer : testServerConfig {
1106
+ start : true ,
1107
+ responses : map [string ]testServerResponse {
1108
+ "/test.runtime.cluster.x-k8s.io/v1alpha1/retryablefakehook/first-extension.*" : response (runtimehooksv1 .ResponseStatusSuccess ),
1109
+ "/test.runtime.cluster.x-k8s.io/v1alpha1/retryablefakehook/second-extension.*" : retryResponse (runtimehooksv1 .ResponseStatusSuccess , 1 ),
1110
+ // third-extension has no handler.
1111
+ },
1112
+ },
1113
+ args : args {
1114
+ hook : fakev1alpha1 .RetryableFakeHook ,
1115
+ request : & fakev1alpha1.RetryableFakeRequest {},
1116
+ response : & fakev1alpha1.RetryableFakeResponse {},
1117
+ },
1118
+ },
1119
+ {
1120
+ name : "should succeed and wait on blocking serial handler, which is called with priority" ,
1121
+ registeredExtensionConfigs : []runtimev1.ExtensionConfig {* secondBlockingWithPriorityConfig },
1122
+ testServer : testServerConfig {
1123
+ start : true ,
1124
+ responses : map [string ]testServerResponse {
1125
+ "/test.runtime.cluster.x-k8s.io/v1alpha1/retryablefakehook/second-extension.*" : retryResponse (runtimehooksv1 .ResponseStatusSuccess , 1 ),
1126
+ // second and third extension has no handler.
1127
+ },
1128
+ },
1129
+ args : args {
1130
+ hook : fakev1alpha1 .RetryableFakeHook ,
1131
+ request : & fakev1alpha1.RetryableFakeRequest {},
1132
+ response : & fakev1alpha1.RetryableFakeResponse {},
1133
+ },
1134
+ },
1075
1135
{
1076
1136
name : "should fail when one of the ExtensionHandlers returns 404" ,
1077
1137
registeredExtensionConfigs : []runtimev1.ExtensionConfig {extensionConfig },
@@ -1317,6 +1377,20 @@ func response(status runtimehooksv1.ResponseStatus) testServerResponse {
1317
1377
}
1318
1378
}
1319
1379
1380
+ func retryResponse (status runtimehooksv1.ResponseStatus , retrySeconds int32 ) testServerResponse {
1381
+ return testServerResponse {
1382
+ response : & fakev1alpha1.RetryableFakeResponse {
1383
+ CommonRetryResponse : runtimehooksv1.CommonRetryResponse {
1384
+ RetryAfterSeconds : retrySeconds ,
1385
+ CommonResponse : runtimehooksv1.CommonResponse {
1386
+ Status : status ,
1387
+ },
1388
+ },
1389
+ },
1390
+ responseStatusCode : http .StatusOK ,
1391
+ }
1392
+ }
1393
+
1320
1394
func createSecureTestServer (server testServerConfig , callbacks ... func ()) * httptest.Server {
1321
1395
mux := http .NewServeMux ()
1322
1396
mux .HandleFunc ("/" , func (w http.ResponseWriter , r * http.Request ) {
@@ -1335,7 +1409,10 @@ func createSecureTestServer(server testServerConfig, callbacks ...func()) *httpt
1335
1409
panic (err )
1336
1410
}
1337
1411
w .WriteHeader (resp .responseStatusCode )
1338
- _ , _ = w .Write (respBody )
1412
+ _ , err = w .Write (respBody )
1413
+ if err != nil {
1414
+ panic (err )
1415
+ }
1339
1416
return
1340
1417
}
1341
1418
0 commit comments