Fix SetFeatureGateDuringTest handling of Parallel tests

Stop using defer as parallel subtest will might result in main test
finishing before subtest.

Fatal when same flag is set twice.

Kubernetes-commit: 9fcf279e2b91e7549190a433373f256fb5aebe85
This commit is contained in:
Marek Siarkowicz 2024-03-05 21:56:40 +01:00 committed by Kubernetes Publisher
parent 469611c7d7
commit 3a83dc12eb
2 changed files with 6 additions and 7 deletions

View File

@ -53,8 +53,6 @@ func TestSerializeObjectParallel(t *testing.T) {
type test struct {
name string
compressionEnabled bool
mediaType string
out []byte
outErrs []error
@ -67,10 +65,9 @@ func TestSerializeObjectParallel(t *testing.T) {
}
newTest := func() test {
return test{
name: "compress on gzip",
compressionEnabled: true,
out: largePayload,
mediaType: "application/json",
name: "compress on gzip",
out: largePayload,
mediaType: "application/json",
req: &http.Request{
Header: http.Header{
"Accept-Encoding": []string{"gzip"},
@ -85,6 +82,7 @@ func TestSerializeObjectParallel(t *testing.T) {
},
}
}
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.APIResponseCompression, true)()
for i := 0; i < 100; i++ {
ctt := newTest()
t.Run(ctt.name, func(t *testing.T) {
@ -94,7 +92,6 @@ func TestSerializeObjectParallel(t *testing.T) {
}
}()
t.Parallel()
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.APIResponseCompression, ctt.compressionEnabled)()
encoder := &fakeEncoder{
buf: ctt.out,

View File

@ -173,6 +173,8 @@ func TestList(t *testing.T) {
}
func TestListWithListFromCache(t *testing.T) {
// TODO(https://github.com/etcd-io/etcd/issues/17507): Remove skip.
t.Skip("This test flakes flakes due to https://github.com/etcd-io/etcd/issues/17507")
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ConsistentListFromCache, true)()
ctx, cacher, server, terminate := testSetupWithEtcdServer(t)
t.Cleanup(terminate)