tarantool / cartridge-springdata

Spring Data Tarantool
Other
18 stars 7 forks source link

Flaky tests for BookRespository #39

Closed akudiyar closed 2 years ago

akudiyar commented 3 years ago

See the last run results https://github.com/tarantool/cartridge-springdata/actions/runs/664124454

vrogach2020 commented 3 years ago

Most likely reason of this tests flakin is that crud reads data from replica before they have been replicated there. Need to reproduce this case and check. If so the following workaraound retrying method for selects can be used:


public class FlakyTestWa {

    public static <T> Optional<T> execWithRetry(int tries, Supplier<Optional<T>> fn) {
        Optional<T> result;
        int c = 0;
        do {
            result = fn.get();
        } while (c < tries && !result.isPresent());
        return result;
    }
}

...
        //first entity must be returned
        Optional<BookStore> bookStoreRecord = execWithRetry(3, () ->
                bookStoreRepository.findById(BookStoreId.builder()
                .bookId(1)
                .receivedAt(ts).build())
        );

        assertThat(bookStoreRecord).hasValueSatisfying(actual -> {
            assertThat(actual.getBookId()).isEqualTo(1);
            assertThat(actual.getStoreNumber()).isEqualTo(123);
            assertThat(actual.getReceivedAt()).isEqualTo(ts);
        });
...
vrogach2020 commented 2 years ago

Should be fixed by https://github.com/tarantool/cartridge-springdata/commit/b230551938351152fe786b59e86fc2a083d397cc