From 188d7a5107aceb6d80e71c28d5c89149a710f31a Mon Sep 17 00:00:00 2001 From: Alex Hong <9397363+hongalex@users.noreply.github.com> Date: Fri, 31 Mar 2023 14:40:36 -0700 Subject: [PATCH] test(pubsub): add retry guard to topic retention test --- pubsub/integration_test.go | 91 ++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 47 deletions(-) diff --git a/pubsub/integration_test.go b/pubsub/integration_test.go index 595557add413..85a7d32e1705 100644 --- a/pubsub/integration_test.go +++ b/pubsub/integration_test.go @@ -1956,57 +1956,54 @@ func TestIntegration_TopicRetention(t *testing.T) { c := integrationTestClient(ctx, t) defer c.Close() - tc := TopicConfig{ - RetentionDuration: 50 * time.Minute, - } - topic, err := c.CreateTopicWithConfig(ctx, topicIDs.New(), &tc) - if err != nil { - t.Fatal(err) - } - defer topic.Delete(ctx) - defer topic.Stop() - - cfg, err := topic.Config(ctx) - if err != nil { - t.Fatal(err) - } + testutil.Retry(t, 5, 1*time.Second, func(r *testutil.R) { + tc := TopicConfig{ + RetentionDuration: 50 * time.Minute, + } + topic, err := c.CreateTopicWithConfig(ctx, topicIDs.New(), &tc) + if err != nil { + r.Errorf("failed to create topic: %v", err) + } + defer topic.Delete(ctx) + defer topic.Stop() - newDur := 11 * time.Minute - cfg, err = topic.Update(ctx, TopicConfigToUpdate{ - RetentionDuration: newDur, - }) - if err != nil { - t.Fatal(err) - } - if got := cfg.RetentionDuration; got != newDur { - t.Fatalf("cfg.RetentionDuration, got: %v, want: %v", got, newDur) - } + newDur := 11 * time.Minute + cfg, err := topic.Update(ctx, TopicConfigToUpdate{ + RetentionDuration: newDur, + }) + if err != nil { + r.Errorf("failed to update topic: %v", err) + } + if got := cfg.RetentionDuration; got != newDur { + r.Errorf("cfg.RetentionDuration, got: %v, want: %v", got, newDur) + } - // Create a subscription on the topic and read TopicMessageRetentionDuration. - s, err := c.CreateSubscription(ctx, subIDs.New(), SubscriptionConfig{ - Topic: topic, - }) - if err != nil { - t.Fatal(err) - } - sCfg, err := s.Config(ctx) - if err != nil { - t.Fatal(err) - } - if got := sCfg.TopicMessageRetentionDuration; got != newDur { - t.Fatalf("sCfg.TopicMessageRetentionDuration, got: %v, want: %v", got, newDur) - } + // Create a subscription on the topic and read TopicMessageRetentionDuration. + s, err := c.CreateSubscription(ctx, subIDs.New(), SubscriptionConfig{ + Topic: topic, + }) + if err != nil { + r.Errorf("failed to create subscription: %v", err) + } + sCfg, err := s.Config(ctx) + if err != nil { + r.Errorf("failed to get sub config: %v", err) + } + if got := sCfg.TopicMessageRetentionDuration; got != newDur { + r.Errorf("sCfg.TopicMessageRetentionDuration, got: %v, want: %v", got, newDur) + } - // Clear retention duration by setting to a negative value. - cfg, err = topic.Update(ctx, TopicConfigToUpdate{ - RetentionDuration: -1 * time.Minute, + // Clear retention duration by setting to a negative value. + cfg, err = topic.Update(ctx, TopicConfigToUpdate{ + RetentionDuration: -1 * time.Minute, + }) + if err != nil { + t.Fatal(err) + } + if got := cfg.RetentionDuration; got != nil { + t.Fatalf("expected cleared retention duration, got: %v", got) + } }) - if err != nil { - t.Fatal(err) - } - if got := cfg.RetentionDuration; got != nil { - t.Fatalf("expected cleared retention duration, got: %v", got) - } } func TestIntegration_ExactlyOnceDelivery_PublishReceive(t *testing.T) {