Skip to content

Commit 0ff24eb

Browse files
authored
Merge pull request #24 from cloudscale-ch/denis/await-ns-rmoval
Wait for namespaces to be removed at the end of tests
2 parents 5238b24 + a99acc5 commit 0ff24eb

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

pkg/internal/integration/main_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ import (
1616
"github.com/stretchr/testify/suite"
1717
"golang.org/x/oauth2"
1818
v1 "k8s.io/api/core/v1"
19+
k8serrors "k8s.io/apimachinery/pkg/api/errors"
1920
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
"k8s.io/apimachinery/pkg/util/wait"
2022
"k8s.io/client-go/kubernetes"
2123
"k8s.io/client-go/tools/clientcmd"
2224
)
@@ -181,6 +183,39 @@ func (s *IntegrationTestSuite) TearDownTest() {
181183
errors++
182184
}
183185

186+
// Wait up to two minutes for the namespace to be deleted
187+
timeout := 120 * time.Second
188+
189+
ctx, cancel := context.WithTimeout(context.Background(), timeout)
190+
defer cancel()
191+
192+
err = wait.PollUntilContextCancel(ctx, 1*time.Second, true,
193+
func(ctx context.Context) (bool, error) {
194+
_, err := s.k8s.CoreV1().Namespaces().Get(
195+
ctx,
196+
s.ns,
197+
metav1.GetOptions{},
198+
)
199+
200+
// Not found, we are done
201+
if k8serrors.IsNotFound(err) {
202+
return true, nil
203+
}
204+
205+
// Another error, fail
206+
if err != nil {
207+
return false, err
208+
}
209+
210+
// Found, try again
211+
return false, nil
212+
})
213+
214+
if err != nil {
215+
s.T().Logf("took too long to delete namespace %s: %s", s.ns, err)
216+
errors++
217+
}
218+
184219
if errors > 0 {
185220
panic(fmt.Sprintf("failed cleanup test: %d errors", errors))
186221
}

0 commit comments

Comments
 (0)