Skip to content

Commit 3aaffb4

Browse files
authored
fix(e2e): race condition causes tests to fail (#1603)
1 parent 1b1efa1 commit 3aaffb4

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

test/e2e/support-bundle/goldpinger_collector_e2e_test.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import (
1616
"github.com/replicatedhq/troubleshoot/pkg/convert"
1717
"github.com/stretchr/testify/assert"
1818
"github.com/stretchr/testify/require"
19-
v1 "k8s.io/api/core/v1"
20-
"sigs.k8s.io/e2e-framework/klient/k8s/resources"
19+
appsv1 "k8s.io/api/apps/v1"
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2121
"sigs.k8s.io/e2e-framework/klient/wait"
2222
"sigs.k8s.io/e2e-framework/klient/wait/conditions"
2323
"sigs.k8s.io/e2e-framework/pkg/envconf"
@@ -48,6 +48,7 @@ func Test_GoldpingerCollector(t *testing.T) {
4848
feature := features.New("Goldpinger collector and analyser").
4949
Setup(func(ctx context.Context, t *testing.T, c *envconf.Config) context.Context {
5050
cluster := getClusterFromContext(t, ctx, ClusterName)
51+
5152
manager := helm.New(cluster.GetKubeconfig())
5253
err := manager.RunInstall(
5354
helm.WithName(releaseName),
@@ -57,22 +58,21 @@ func Test_GoldpingerCollector(t *testing.T) {
5758
helm.WithTimeout("2m"),
5859
)
5960
require.NoError(t, err)
61+
6062
client, err := c.NewClient()
6163
require.NoError(t, err)
62-
pods := &v1.PodList{}
6364

6465
// Lets wait for the goldpinger pods to be running
65-
err = client.Resources().WithNamespace(c.Namespace()).List(ctx, pods,
66-
resources.WithLabelSelector("app.kubernetes.io/name=goldpinger"),
67-
)
68-
require.NoError(t, err)
69-
require.Len(t, pods.Items, 1)
70-
66+
ds := &appsv1.DaemonSet{ObjectMeta: metav1.ObjectMeta{Name: "goldpinger", Namespace: c.Namespace()}}
7167
err = wait.For(
72-
conditions.New(client.Resources()).PodRunning(&pods.Items[0]),
68+
conditions.New(client.Resources()).DaemonSetReady(ds),
7369
wait.WithTimeout(time.Second*30),
7470
)
7571
require.NoError(t, err)
72+
73+
// HACK: wait for goldpinger to do its thing
74+
time.Sleep(time.Second * 30)
75+
7676
return ctx
7777
}).
7878
Assess("collect and analyse goldpinger pings", func(ctx context.Context, t *testing.T, c *envconf.Config) context.Context {
@@ -108,7 +108,7 @@ func Test_GoldpingerCollector(t *testing.T) {
108108
// Check that we analysed collected goldpinger results.
109109
// We should expect a single analysis result for goldpinger.
110110
assert.Equal(t, 1, len(analysisResults))
111-
assert.True(t, strings.HasPrefix(analysisResults[0].Name, "missing.ping.results.for.goldpinger."))
111+
assert.True(t, strings.HasPrefix(analysisResults[0].Name, "pings.to.goldpinger."))
112112
if t.Failed() {
113113
t.Logf("Analysis results: %s\n", analysisJSON)
114114
t.Logf("Stdout: %s\n", out.String())
@@ -121,7 +121,8 @@ func Test_GoldpingerCollector(t *testing.T) {
121121
Teardown(func(ctx context.Context, t *testing.T, c *envconf.Config) context.Context {
122122
cluster := getClusterFromContext(t, ctx, ClusterName)
123123
manager := helm.New(cluster.GetKubeconfig())
124-
manager.RunUninstall(helm.WithName(releaseName), helm.WithNamespace(c.Namespace()))
124+
err := manager.RunUninstall(helm.WithName(releaseName), helm.WithNamespace(c.Namespace()))
125+
require.NoError(t, err)
125126
return ctx
126127
}).
127128
Feature()

test/e2e/support-bundle/helm_collector_e2e_test.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616

1717
collect "github.com/replicatedhq/troubleshoot/pkg/collect"
1818
"github.com/stretchr/testify/assert"
19+
"github.com/stretchr/testify/require"
1920
)
2021

2122
var curDir, _ = os.Getwd()
@@ -27,8 +28,15 @@ func Test_HelmCollector(t *testing.T) {
2728
Setup(func(ctx context.Context, t *testing.T, c *envconf.Config) context.Context {
2829
cluster := getClusterFromContext(t, ctx, ClusterName)
2930
manager := helm.New(cluster.GetKubeconfig())
30-
manager.RunInstall(helm.WithName(releaseName), helm.WithNamespace(c.Namespace()), helm.WithChart(filepath.Join(curDir, "testdata/charts/nginx-15.2.0.tgz")), helm.WithArgs("-f "+filepath.Join(curDir, "testdata/helm-values.yaml")), helm.WithWait(), helm.WithTimeout("1m"))
31-
//ignore error to allow test to speed up, helm collector will catch the pending or deployed helm release status
31+
manager.RunInstall(
32+
helm.WithName(releaseName),
33+
helm.WithNamespace(c.Namespace()),
34+
helm.WithChart(filepath.Join(curDir, "testdata/charts/nginx-15.2.0.tgz")),
35+
helm.WithArgs("-f "+filepath.Join(curDir, "testdata/helm-values.yaml")),
36+
helm.WithWait(),
37+
helm.WithTimeout("1m"),
38+
)
39+
// ignore error to allow test to speed up, helm collector will catch the pending or deployed helm release status
3240
return ctx
3341
}).
3442
Assess("check support bundle catch helm release", func(ctx context.Context, t *testing.T, c *envconf.Config) context.Context {
@@ -62,7 +70,7 @@ func Test_HelmCollector(t *testing.T) {
6270
if err != nil {
6371
t.Fatal(err)
6472
}
65-
assert.Equal(t, 1, len(results))
73+
require.Equal(t, 1, len(results))
6674
assert.Equal(t, releaseName, results[0].ReleaseName)
6775
assert.Equal(t, "nginx", results[0].Chart)
6876
assert.Equal(t, map[string]interface{}{"name": "TEST_ENV_VAR", "value": "test-value"}, results[0].VersionInfo[0].Values["extraEnvVars"].([]interface{})[0])
@@ -72,7 +80,8 @@ func Test_HelmCollector(t *testing.T) {
7280
Teardown(func(ctx context.Context, t *testing.T, c *envconf.Config) context.Context {
7381
cluster := getClusterFromContext(t, ctx, ClusterName)
7482
manager := helm.New(cluster.GetKubeconfig())
75-
manager.RunUninstall(helm.WithName(releaseName), helm.WithNamespace(c.Namespace()))
83+
err := manager.RunUninstall(helm.WithName(releaseName), helm.WithNamespace(c.Namespace()))
84+
require.NoError(t, err)
7685
return ctx
7786
}).
7887
Feature()

0 commit comments

Comments
 (0)