Skip to content

Commit 48f23e4

Browse files
committed
Reorder steps to clear cache
1 parent e463df4 commit 48f23e4

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

tests/helpers_test.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,18 @@ func setupPhone(ctx context.Context, t *testing.T, messagesPerMinute uint) testP
7878
fcmToken := "fcm-" + uuid.New().String()
7979
client := newAPIClient()
8080

81-
_, resp, err := client.Phones.Upsert(ctx, &httpsms.PhoneUpsertParams{
81+
// Create the phone API key first so that a few seconds pass (during phone upsert)
82+
// before we use it, giving the cache time to clear.
83+
apiKeyResp, resp, err := client.PhoneAPIKeys.Store(ctx, &httpsms.PhoneAPIKeyStoreParams{
84+
Name: "test-key-" + uuid.New().String(),
85+
})
86+
require.NoError(t, err)
87+
require.Equal(t, http.StatusOK, resp.HTTPResponse.StatusCode, "phone api key store failed")
88+
89+
phoneAPIKeyValue := apiKeyResp.Data.APIKey
90+
require.NotEmpty(t, phoneAPIKeyValue)
91+
92+
_, resp, err = client.Phones.Upsert(ctx, &httpsms.PhoneUpsertParams{
8293
PhoneNumber: phoneNumber,
8394
FcmToken: fcmToken,
8495
MessagesPerMinute: messagesPerMinute,
@@ -89,15 +100,6 @@ func setupPhone(ctx context.Context, t *testing.T, messagesPerMinute uint) testP
89100
require.NoError(t, err)
90101
require.Equal(t, http.StatusOK, resp.HTTPResponse.StatusCode, "phone upsert failed")
91102

92-
apiKeyResp, resp, err := client.PhoneAPIKeys.Store(ctx, &httpsms.PhoneAPIKeyStoreParams{
93-
Name: "test-key-" + uuid.New().String(),
94-
})
95-
require.NoError(t, err)
96-
require.Equal(t, http.StatusOK, resp.HTTPResponse.StatusCode, "phone api key store failed")
97-
98-
phoneAPIKeyValue := apiKeyResp.Data.APIKey
99-
require.NotEmpty(t, phoneAPIKeyValue)
100-
101103
phoneClient := newPhoneClient(phoneAPIKeyValue)
102104
_, resp, err = phoneClient.Phones.UpsertFCMToken(ctx, &httpsms.PhoneFCMTokenParams{
103105
PhoneNumber: phoneNumber,

0 commit comments

Comments
 (0)