Skip to content

Commit

Permalink
Fix swapIndexes flaky tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoocasali committed Dec 20, 2023
1 parent 16b854d commit 706302e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
8 changes: 0 additions & 8 deletions test/models/test_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,10 @@ class TestMeiliSearchClient extends MeiliSearchClient {
}

Future<void> disposeUsedResources() async {
final indexesCopy = usedIndexes.toList();
await Future.wait([
_deleteUsedIndexes(),
_deleteUsedKeys(),
]);
if (indexesCopy.isNotEmpty) {
await _deleteTasksForDeletedIndexes(indexesCopy);
}
}

Future<void> _deleteUsedIndexes() async {
Expand All @@ -131,8 +127,4 @@ class TestMeiliSearchClient extends MeiliSearchClient {
),
);
}

Future<void> _deleteTasksForDeletedIndexes(List<String> indexes) async {
await deleteTasks(params: DeleteTasksQuery(indexUids: indexes));
}
}
13 changes: 10 additions & 3 deletions test/swaps_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,28 @@ void main() {
setUpClient();

test('swaps indexes from input', () async {
var books = ['books', 'books_new'];
var movies = ['movies', 'movies_new'];
var books = [randomUid('books'), randomUid('books_new')];
var movies = [randomUid('movies'), randomUid('movies_new')];
var swaps = [SwapIndex(books), SwapIndex(movies)];

// first create the indexes to be swapped
for (var index in books + movies) {
await client.createIndex(index).waitFor(client: client);
}

var response = await client
.swapIndexes(
swaps,
deleteWhenDone: false,
)
.waitFor(
client: client,
throwFailed: false,
throwFailed: true,
);

expect(response.type, 'indexSwap');
expect(response.error, null);
expect(response.status, 'succeeded');
expect(response.details!['swaps'], [
{'indexes': books},
{'indexes': movies}
Expand Down

0 comments on commit 706302e

Please sign in to comment.