Commit 02a29453 authored by Maru Newby's avatar Maru Newby

fed: Fix flakey ingress unit test

The unit test for the ingress controller was previously adding a cluster twice, which resulted in a cluster being deleted and added back. The deletion was racing the controller shutdown to close informer channels. This change ensures that the informer clears its map of informers when Stop() is called to prevent a double close, and that the test no longer adds the cluster twice.
parent ab9b299c
...@@ -252,14 +252,10 @@ func TestIngressController(t *testing.T) { ...@@ -252,14 +252,10 @@ func TestIngressController(t *testing.T) {
assert.True(t, reflect.DeepEqual(updatedIngress2.Spec, fedIngress.Spec), "Spec of updated ingress is not equal") assert.True(t, reflect.DeepEqual(updatedIngress2.Spec, fedIngress.Spec), "Spec of updated ingress is not equal")
assert.Equal(t, updatedIngress2.ObjectMeta.Annotations["A"], fedIngress.ObjectMeta.Annotations["A"], "Updated annotation not transferred from federated to cluster ingress.") assert.Equal(t, updatedIngress2.ObjectMeta.Annotations["A"], fedIngress.ObjectMeta.Annotations["A"], "Updated annotation not transferred from federated to cluster ingress.")
// Test add cluster
t.Log("Adding a second cluster")
fedIngress.Annotations[staticIPNameKeyWritable] = "foo" // Make sure that the base object has a static IP name first. fedIngress.Annotations[staticIPNameKeyWritable] = "foo" // Make sure that the base object has a static IP name first.
fedIngressWatch.Modify(&fedIngress) fedIngressWatch.Modify(&fedIngress)
clusterWatch.Add(cluster2)
t.Log("Checking that the ingress got created in cluster 2") t.Log("Checking that the ingress got created in cluster 2 after a global ip was assigned")
createdIngress2 := GetIngressFromChan(t, cluster2IngressCreateChan) createdIngress2 := GetIngressFromChan(t, cluster2IngressCreateChan)
assert.NotNil(t, createdIngress2) assert.NotNil(t, createdIngress2)
assert.True(t, reflect.DeepEqual(fedIngress.Spec, createdIngress2.Spec), "Spec of created ingress is not equal") assert.True(t, reflect.DeepEqual(fedIngress.Spec, createdIngress2.Spec), "Spec of created ingress is not equal")
......
...@@ -281,6 +281,10 @@ func (f *federatedInformerImpl) Stop() { ...@@ -281,6 +281,10 @@ func (f *federatedInformerImpl) Stop() {
for key, informer := range f.targetInformers { for key, informer := range f.targetInformers {
glog.V(4).Infof("... Closing informer channel for %q.", key) glog.V(4).Infof("... Closing informer channel for %q.", key)
close(informer.stopChan) close(informer.stopChan)
// Remove each informer after it has been stopped to prevent
// subsequent cluster deletion from attempting to double close
// an informer's stop channel.
delete(f.targetInformers, key)
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment