Skip to content

Commit 3aae3b7

Browse files
committed
go.d/k8s_state: wait for informer events in the chart ownership tests
1 parent eff0408 commit 3aae3b7

1 file changed

Lines changed: 28 additions & 6 deletions

File tree

‎src/go/plugin/go.d/collector/k8s_state/collector_test.go‎

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,10 +1025,6 @@ func TestCollector_Collect_DeleteObjectKeepsLongerNamedSibling(t *testing.T) {
10251025
)
10261026
collr, deletedOnly, liveOnly := collrs[0], collrs[1], collrs[2]
10271027

1028-
require.NoError(t, test.delete(client, deleted))
1029-
time.Sleep(time.Second)
1030-
_ = collr.Collect(ctx)
1031-
10321028
expected := make(map[string]bool) // chart ID -> obsolete
10331029
for _, c := range *deletedOnly.Charts() {
10341030
expected[c.ID] = true
@@ -1037,6 +1033,25 @@ func TestCollector_Collect_DeleteObjectKeepsLongerNamedSibling(t *testing.T) {
10371033
for _, c := range *liveOnly.Charts() {
10381034
expected[c.ID] = false
10391035
}
1036+
var own int
1037+
for _, obsolete := range expected {
1038+
if obsolete {
1039+
own++
1040+
}
1041+
}
1042+
require.NotZero(t, own, "the deleted object must have charts")
1043+
1044+
require.NoError(t, test.delete(client, deleted))
1045+
require.Eventually(t, func() bool {
1046+
_ = collr.Collect(ctx)
1047+
for id, obsolete := range expected {
1048+
if c := collr.Charts().Get(id); obsolete && (c == nil || !c.Obsolete) {
1049+
return false
1050+
}
1051+
}
1052+
return true
1053+
}, 5*time.Second, 50*time.Millisecond, "the deleted object's charts were not removed")
1054+
10401055
actual := make(map[string]bool)
10411056
for _, c := range *collr.Charts() {
10421057
actual[c.ID] = c.Obsolete
@@ -1057,8 +1072,15 @@ func TestCollector_Collect_ScheduledPodUpdatesOnlyItsNodeLabel(t *testing.T) {
10571072

10581073
_, err := client.CoreV1().Pods(pending.Namespace).Update(ctx, newPod("node01", "x-1"), metav1.UpdateOptions{})
10591074
require.NoError(t, err)
1060-
time.Sleep(time.Millisecond * 50)
1061-
_ = collr.Collect(ctx)
1075+
require.Eventually(t, func() bool {
1076+
_ = collr.Collect(ctx)
1077+
for _, c := range *collr.Charts() {
1078+
if chartLabelValue(c, labelKeyPodName) == "x-1" && chartLabelValue(c, labelKeyNodeName) != "node01" {
1079+
return false
1080+
}
1081+
}
1082+
return true
1083+
}, 5*time.Second, 50*time.Millisecond, "the scheduled pod's charts did not get its node label")
10621084

10631085
podNode := map[string]string{"x-1": "node01", "x-10": "node02"}
10641086
seen := make(map[string]bool)

0 commit comments

Comments
 (0)