Set integration tests to use distinct namespaces
TestWatchBasedManager was racing with the default namespace creation. To fix that flake and to ensure integration tests using a shared etcd don't accidentally overlap in the future, move the three main tests using the default namespace to separate namespaces, and have TestWatchBasedManager create that namespace before it runs. Make StartTestServer wait for default namespace creation, which will reduce other flakes until future changes completely remove use of default namespace. From a failed integration run: watch_manager_test.go:66: namespaces "default" not found watch_manager_test.go:66: namespaces "default" not found watch_manager_test.go:66: namespaces "default" not found
This commit is contained in:
@@ -22,7 +22,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
@@ -35,6 +35,7 @@ import (
|
||||
)
|
||||
|
||||
func TestWatchBasedManager(t *testing.T) {
|
||||
testNamespace := "test-watch-based-manager"
|
||||
server := kubeapiservertesting.StartTestServerOrDie(t, nil, nil, framework.SharedEtcd())
|
||||
defer server.TearDownFn()
|
||||
|
||||
@@ -43,6 +44,9 @@ func TestWatchBasedManager(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if _, err := client.CoreV1().Namespaces().Create((&v1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: testNamespace}})); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
listObj := func(namespace string, options metav1.ListOptions) (runtime.Object, error) {
|
||||
return client.CoreV1().Secrets(namespace).List(options)
|
||||
@@ -62,7 +66,7 @@ func TestWatchBasedManager(t *testing.T) {
|
||||
defer wg.Done()
|
||||
for j := 0; j < 100; j++ {
|
||||
name := fmt.Sprintf("s%d", i*100+j)
|
||||
if _, err := client.CoreV1().Secrets("default").Create(&v1.Secret{ObjectMeta: metav1.ObjectMeta{Name: name}}); err != nil {
|
||||
if _, err := client.CoreV1().Secrets(testNamespace).Create(&v1.Secret{ObjectMeta: metav1.ObjectMeta{Name: name}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -81,9 +85,9 @@ func TestWatchBasedManager(t *testing.T) {
|
||||
for j := 0; j < 100; j++ {
|
||||
name := fmt.Sprintf("s%d", i*100+j)
|
||||
start := time.Now()
|
||||
store.AddReference("default", name)
|
||||
store.AddReference(testNamespace, name)
|
||||
err := wait.PollImmediate(10*time.Millisecond, 10*time.Second, func() (bool, error) {
|
||||
obj, err := store.Get("default", name)
|
||||
obj, err := store.Get(testNamespace, name)
|
||||
if err != nil {
|
||||
t.Logf("failed on %s, retrying: %v", name, err)
|
||||
return false, nil
|
||||
|
Reference in New Issue
Block a user