Skip to content

Commit

Permalink
Cleanup and reduce test duration (#284)
Browse files Browse the repository at this point in the history
Followup #277
  • Loading branch information
deepthidevaki authored Dec 8, 2022
2 parents b072579 + 07cd4a6 commit 297c2a7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 15 deletions.
9 changes: 0 additions & 9 deletions go-chaos/internal/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,6 @@ func (c K8Client) CreatePodWithLabelsAndName(t *testing.T, selector *metav1.Labe
require.NoError(t, err)
}

func (c K8Client) CreateReadyPodWithLabelsAndName(t *testing.T, selector *metav1.LabelSelector, podName string) {
_, err := c.Clientset.CoreV1().Pods(c.GetCurrentNamespace()).Create(context.TODO(), &v1.Pod{
ObjectMeta: metav1.ObjectMeta{Labels: selector.MatchLabels, Name: podName},
Spec: v1.PodSpec{},
}, metav1.CreateOptions{})

require.NoError(t, err)
}

func (c K8Client) CreateBrokerPodsWithStatus(t *testing.T, selector *metav1.LabelSelector, podName string, podPhase v1.PodPhase, readyStatus bool) {
_, err := c.Clientset.CoreV1().Pods(c.GetCurrentNamespace()).Create(context.TODO(), &v1.Pod{
ObjectMeta: metav1.ObjectMeta{Labels: selector.MatchLabels, Name: podName},
Expand Down
6 changes: 3 additions & 3 deletions go-chaos/internal/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@ func (c K8Client) RestartPodWithGracePeriod(podName string, gracePeriodSec *int6
}

func (c K8Client) AwaitReadiness() error {
return c.AwaitReadinessWithTimeout(5 * time.Minute)
return c.AwaitReadinessWithTimeout(5*time.Minute, 1*time.Second)
}

func (c K8Client) AwaitReadinessWithTimeout(timeout time.Duration) error {
func (c K8Client) AwaitReadinessWithTimeout(timeout time.Duration, tickTime time.Duration) error {
timedOut := time.After(timeout)
ticker := time.Tick(1 * time.Second)
ticker := time.Tick(tickTime)

// Keep checking until we're timed out
for {
Expand Down
6 changes: 3 additions & 3 deletions go-chaos/internal/pods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ func Test_ShouldReturnTrueWhenBrokersAreReady(t *testing.T) {
k8Client.CreateDeploymentWithLabelsAndName(t, gatewaySelector, "gateway")

// when
err = k8Client.AwaitReadinessWithTimeout(2 * time.Second)
err = k8Client.AwaitReadinessWithTimeout(100*time.Millisecond, 1*time.Millisecond)

// then
require.NoError(t, err)
Expand All @@ -304,7 +304,7 @@ func Test_ShouldReturnErrorWhenAtleastOneBrokerIsNotReady(t *testing.T) {
k8Client.CreateDeploymentWithLabelsAndName(t, gatewaySelector, "gateway")

// when
err = k8Client.AwaitReadinessWithTimeout(2 * time.Second)
err = k8Client.AwaitReadinessWithTimeout(100*time.Millisecond, 1*time.Second)

// then
require.Error(t, err)
Expand All @@ -325,7 +325,7 @@ func Test_ShouldReturnErrorWhenAtleastOneBrokerIsNotRunning(t *testing.T) {
k8Client.CreateDeploymentWithLabelsAndName(t, gatewaySelector, "gateway")

// when
err = k8Client.AwaitReadinessWithTimeout(2 * time.Second)
err = k8Client.AwaitReadinessWithTimeout(100*time.Millisecond, 1*time.Second)

// then
require.Error(t, err)
Expand Down

0 comments on commit 297c2a7

Please sign in to comment.