Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(pubsub): add retry guard to topic retention test #7670

Merged
merged 3 commits into from
Apr 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 44 additions & 47 deletions pubsub/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down