Skip to content

Commit

Permalink
tests: Add a delay after creating a Firestore index
Browse files Browse the repository at this point in the history
Currently the LRO returns before the index is *really* ready to use.
  • Loading branch information
jskeet committed Sep 27, 2024
1 parent ad55478 commit 001c246
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public class FirestoreFixture : CloudProjectFixtureBase, ICollectionFixture<Fire
private static readonly PollSettings AdminOperationPollSettings =
new PollSettings(expiration: Expiration.FromTimeout(TimeSpan.FromMinutes(5)), delay: TimeSpan.FromSeconds(5));

// How long we should wait after creating an index, before returning to the caller
// (who is expecting to be able to use the index immediately). Sometimes the CreateIndex operation
// returns before the index is *really* ready. A short delay fixes this.
private static readonly TimeSpan PostIndexCreationDelay = TimeSpan.FromSeconds(20);

private const string DatabaseLocation = "us-east1";

// This is not the test project environment variable used by other integration tests,
Expand Down Expand Up @@ -143,6 +148,7 @@ internal async Task CreateIndexAsync(CollectionReference collection, params Inde
};
var job = await AdminClient.CreateIndexAsync(new CollectionGroupName(ProjectId, DatabaseId, collection.Id), index);
await job.PollUntilCompletedAsync(AdminOperationPollSettings);
await Task.Delay(PostIndexCreationDelay);
}

private async Task PopulateCollection(CollectionReference collection, IEnumerable<object> documents)
Expand Down

0 comments on commit 001c246

Please sign in to comment.