From 436790ccd1ada0b10d788ac7cc2ead79a75185fd Mon Sep 17 00:00:00 2001 From: James DeFelice Date: Tue, 24 Feb 2015 13:21:09 -0500 Subject: [PATCH 1/4] add unit test for #4757 fixed compilation error --- pkg/registry/pod/etcd/etcd_test.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/pkg/registry/pod/etcd/etcd_test.go b/pkg/registry/pod/etcd/etcd_test.go index e1a8141c98f..5bd7dbcec7d 100644 --- a/pkg/registry/pod/etcd/etcd_test.go +++ b/pkg/registry/pod/etcd/etcd_test.go @@ -24,6 +24,7 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors" + etcderrors "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors/etcd" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/rest/resttest" "github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver" @@ -846,6 +847,33 @@ func TestEtcdCreate(t *testing.T) { } } +func TestEtcdCreateBindingNoPod(t *testing.T) { + registry, bindingRegistry, fakeClient, _ := newStorage(t) + ctx := api.NewDefaultContext() + fakeClient.TestIndex = true + + key, _ := registry.store.KeyFunc(ctx, "foo") + fakeClient.Data[key] = tools.EtcdResponseWithError{ + R: &etcd.Response{ + Node: nil, + }, + E: tools.EtcdErrorNotFound, + } + // Assume that a pod has undergone the following: + // - Create (apiserver) + // - Schedule (scheduler) + // - Delete (apiserver) + _, err := bindingRegistry.Create(ctx, &api.Binding{PodID: "foo", Host: "machine", ObjectMeta: api.ObjectMeta{Namespace: api.NamespaceDefault}}) + if !errors.IsNotFound(etcderrors.InterpretGetError(err, "Pod", "foo")) { + t.Fatalf("Unexpected error returned: %#v", err) + } + + _, err = registry.Get(ctx, "foo") + if !errors.IsNotFound(etcderrors.InterpretGetError(err, "Pod", "foo")) { + t.Fatalf("Unexpected error: %v", err) + } +} + func TestEtcdCreateFailsWithoutNamespace(t *testing.T) { registry, _, _, fakeClient, _ := newStorage(t) fakeClient.TestIndex = true From e5350d61a815ad28c9e8065d73b3048a6f80955d Mon Sep 17 00:00:00 2001 From: James DeFelice Date: Mon, 2 Mar 2015 11:53:23 -0500 Subject: [PATCH 2/4] added comment suggested by @davidopp --- pkg/registry/pod/etcd/etcd_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/registry/pod/etcd/etcd_test.go b/pkg/registry/pod/etcd/etcd_test.go index 5bd7dbcec7d..f06b9fc829c 100644 --- a/pkg/registry/pod/etcd/etcd_test.go +++ b/pkg/registry/pod/etcd/etcd_test.go @@ -847,6 +847,8 @@ func TestEtcdCreate(t *testing.T) { } } +// Ensure that when scheduler creates a binding for a pod that has already been deleted +// by the API server, API server returns not-found error. func TestEtcdCreateBindingNoPod(t *testing.T) { registry, bindingRegistry, fakeClient, _ := newStorage(t) ctx := api.NewDefaultContext() From 4943fe937b3b6754e6a7517cf09bf46d1da86ee3 Mon Sep 17 00:00:00 2001 From: James DeFelice Date: Fri, 6 Mar 2015 07:02:04 +0000 Subject: [PATCH 3/4] implemented nil err checks, cc @yujuhong @davidopp --- pkg/registry/pod/etcd/etcd_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/registry/pod/etcd/etcd_test.go b/pkg/registry/pod/etcd/etcd_test.go index f06b9fc829c..bc744096f5c 100644 --- a/pkg/registry/pod/etcd/etcd_test.go +++ b/pkg/registry/pod/etcd/etcd_test.go @@ -866,11 +866,17 @@ func TestEtcdCreateBindingNoPod(t *testing.T) { // - Schedule (scheduler) // - Delete (apiserver) _, err := bindingRegistry.Create(ctx, &api.Binding{PodID: "foo", Host: "machine", ObjectMeta: api.ObjectMeta{Namespace: api.NamespaceDefault}}) + if err == nil { + t.Fatalf("Expected not-found-error but got nothing") + } if !errors.IsNotFound(etcderrors.InterpretGetError(err, "Pod", "foo")) { t.Fatalf("Unexpected error returned: %#v", err) } _, err = registry.Get(ctx, "foo") + if err == nil { + t.Fatalf("Expected not-found-error but got nothing") + } if !errors.IsNotFound(etcderrors.InterpretGetError(err, "Pod", "foo")) { t.Fatalf("Unexpected error: %v", err) } From bf02d17244b0288306e957c412fa1970cfa5bfdf Mon Sep 17 00:00:00 2001 From: James DeFelice Date: Mon, 9 Mar 2015 14:08:11 +0000 Subject: [PATCH 4/4] rebased to master --- pkg/registry/pod/etcd/etcd_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/registry/pod/etcd/etcd_test.go b/pkg/registry/pod/etcd/etcd_test.go index bc744096f5c..3b6781e5c3e 100644 --- a/pkg/registry/pod/etcd/etcd_test.go +++ b/pkg/registry/pod/etcd/etcd_test.go @@ -850,7 +850,7 @@ func TestEtcdCreate(t *testing.T) { // Ensure that when scheduler creates a binding for a pod that has already been deleted // by the API server, API server returns not-found error. func TestEtcdCreateBindingNoPod(t *testing.T) { - registry, bindingRegistry, fakeClient, _ := newStorage(t) + registry, bindingRegistry, _, fakeClient, _ := newStorage(t) ctx := api.NewDefaultContext() fakeClient.TestIndex = true