11//go:build integration_test
2- // +build integration_test
32
43// ------------------------------------------------------------
54// Copyright (c) Microsoft Corporation and Dapr Contributors.
@@ -26,6 +25,7 @@ import (
2625const (
2726 // Environment variable containing the connection string to Azure Service Bus
2827 testServiceBusEnvKey = "DAPR_TEST_AZURE_SERVICEBUS"
28+ ttlInSeconds = 5
2929)
3030
3131func getTestServiceBusConnectionString () string {
@@ -66,7 +66,7 @@ func TestQueueWithTTL(t *testing.T) {
6666 queueName := uuid .New ().String ()
6767 a := NewAzureServiceBusQueues (logger .NewLogger ("test" ))
6868 m := bindings.Metadata {}
69- m .Properties = map [string ]string {"connectionString" : serviceBusConnectionString , "queueName" : queueName , metadata .TTLMetadataKey : "1" }
69+ m .Properties = map [string ]string {"connectionString" : serviceBusConnectionString , "queueName" : queueName , metadata .TTLMetadataKey : fmt . Sprintf ( "%d" , ttlInSeconds ) }
7070 err := a .Init (m )
7171 assert .Nil (t , err )
7272
@@ -81,16 +81,15 @@ func TestQueueWithTTL(t *testing.T) {
8181
8282 queueEntity , err := qmr .Get (context .Background (), queueName )
8383 assert .Nil (t , err )
84- assert .Equal (t , "PT1S" , * queueEntity .DefaultMessageTimeToLive )
84+ assert .Equal (t , fmt . Sprintf ( "PT%dS" , ttlInSeconds ) , * queueEntity .DefaultMessageTimeToLive )
8585
8686 // Assert that if waited too long, we won't see any message
8787 const tooLateMsgContent = "too_late_msg"
8888 _ , err = a .Invoke (& bindings.InvokeRequest {Data : []byte (tooLateMsgContent )})
8989 assert .Nil (t , err )
9090
91- time .Sleep (time .Second * 2 )
91+ time .Sleep (time .Second * ( ttlInSeconds + 2 ) )
9292
93- const ttlInSeconds = 1
9493 const maxGetDuration = ttlInSeconds * time .Second
9594
9695 _ , ok , err := getMessageWithRetries (queue , maxGetDuration )
@@ -108,7 +107,7 @@ func TestQueueWithTTL(t *testing.T) {
108107 msgBody := string (msg .Data )
109108 assert .Equal (t , testMsgContent , msgBody )
110109 assert .NotNil (t , msg .TTL )
111- assert .Equal (t , time .Second , * msg .TTL )
110+ assert .Equal (t , ttlInSeconds * time .Second , * msg .TTL )
112111}
113112
114113func TestPublishingWithTTL (t * testing.T ) {
@@ -141,15 +140,14 @@ func TestPublishingWithTTL(t *testing.T) {
141140 writeRequest := bindings.InvokeRequest {
142141 Data : []byte (tooLateMsgContent ),
143142 Metadata : map [string ]string {
144- metadata .TTLMetadataKey : "1" ,
143+ metadata .TTLMetadataKey : fmt . Sprintf ( "%d" , ttlInSeconds ) ,
145144 },
146145 }
147146 _ , err = queueBinding1 .Invoke (& writeRequest )
148147 assert .Nil (t , err )
149148
150- time .Sleep (time .Second * 5 )
149+ time .Sleep (time .Second * ( ttlInSeconds + 2 ) )
151150
152- const ttlInSeconds = 1
153151 const maxGetDuration = ttlInSeconds * time .Second
154152
155153 _ , ok , err := getMessageWithRetries (queue , maxGetDuration )
@@ -165,7 +163,7 @@ func TestPublishingWithTTL(t *testing.T) {
165163 writeRequest = bindings.InvokeRequest {
166164 Data : []byte (testMsgContent ),
167165 Metadata : map [string ]string {
168- metadata .TTLMetadataKey : "1" ,
166+ metadata .TTLMetadataKey : fmt . Sprintf ( "%d" , ttlInSeconds ) ,
169167 },
170168 }
171169 _ , err = queueBinding2 .Invoke (& writeRequest )
@@ -178,5 +176,5 @@ func TestPublishingWithTTL(t *testing.T) {
178176 assert .Equal (t , testMsgContent , msgBody )
179177 assert .NotNil (t , msg .TTL )
180178
181- assert .Equal (t , time .Second , * msg .TTL )
179+ assert .Equal (t , ttlInSeconds * time .Second , * msg .TTL )
182180}
0 commit comments