From 3b9a926f69fe2bb95d499f19bf245ac259fb82a5 Mon Sep 17 00:00:00 2001 From: sfrei Date: Wed, 12 Jun 2024 01:31:50 +0200 Subject: [PATCH] Delay tests when running in GH actions to prevent 429 --- CHANGELOG.md | 4 +++ .../sfrei/tracksearch/clients/ClientTest.java | 31 ++++++++++++++++--- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3036567..3c1c7dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ Changelog 0.11.0 - unreleased ------------------- +**Features:** + +- Updated dependencies + **Bugfixes:** - Fix YouTube tracks parsing through parse missing info on demand diff --git a/src/test/java/io/sfrei/tracksearch/clients/ClientTest.java b/src/test/java/io/sfrei/tracksearch/clients/ClientTest.java index b368b02..4bbef51 100644 --- a/src/test/java/io/sfrei/tracksearch/clients/ClientTest.java +++ b/src/test/java/io/sfrei/tracksearch/clients/ClientTest.java @@ -24,6 +24,7 @@ import io.sfrei.tracksearch.tracks.metadata.TrackMetadata; import io.sfrei.tracksearch.tracks.metadata.TrackStream; import lombok.Getter; +import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import org.assertj.core.api.Condition; import org.assertj.core.api.InstanceOfAssertFactories; @@ -49,6 +50,8 @@ @TestMethodOrder(MethodOrderer.OrderAnnotation.class) public abstract class ClientTest, T extends Track> { + private final boolean isGitHubAction; + protected final C trackSearchClient; private final List searchKeys; @@ -65,10 +68,20 @@ public ClientTest(C searchClient, boolean single) { this.trackSearchClient = searchClient; this.searchKeys = single ? List.of(SINGLE_SEARCH_KEY) : SEARCH_KEYS; tracksForSearch = new ArrayList<>(); + + final String gitHubActionsEnv = System.getenv("GITHUB_ACTIONS"); + isGitHubAction = gitHubActionsEnv != null; + + log.info("Tests running in GitHub Actions: {}", isGitHubAction); } public abstract List trackURLs(); + @SneakyThrows + private void delayWhenGitHubAction() { + if (isGitHubAction) Thread.sleep(1000); + } + @Order(1) @ParameterizedTest @MethodSource("trackURLs") @@ -85,7 +98,10 @@ public void clientApplicableForURL(String url) { @ParameterizedTest @MethodSource("trackURLs") public void trackForURL(String url) throws TrackSearchException { - final Track trackForURL = trackSearchClient.getTrack(url); + final T trackForURL = trackSearchClient.getTrack(url); + // Test single directly as resolving might differ from list results + checkTrack(trackForURL); + checkTrackMetadata(trackForURL); checkTrackFormats(trackForURL); } @@ -137,7 +153,7 @@ public void getNextTracks(TrackList trackList) throws TrackSearchException { @ParameterizedTest @MethodSource("getAllTracksFromTrackLists") public void checkTrack(T track) { - log.trace("{}", track.pretty()); + log.trace("Check track: {}", track.pretty()); final SoftAssertions assertions = new SoftAssertions(); @@ -169,7 +185,7 @@ public void checkTrack(T track) { @ParameterizedTest @MethodSource("getAllTracksFromTrackLists") public void checkTrackMetadata(T track) { - log.trace("{}", track.pretty()); + log.trace("Check track metadata: {}", track.pretty()); final SoftAssertions assertions = new SoftAssertions(); final TrackMetadata trackMetadata = track.getTrackMetadata(); @@ -209,7 +225,8 @@ public void checkTrackMetadata(T track) { @ParameterizedTest @MethodSource("getAllTracksFromTrackLists") public void checkTrackFormats(Track track) { - log.trace("{}", track.pretty()); + log.trace("Check track formats: {}", track.pretty()); + delayWhenGitHubAction(); final SoftAssertions assertions = new SoftAssertions(); final List formats = track.getFormats(); @@ -242,6 +259,9 @@ public void checkTrackFormats(Track track) { @ParameterizedTest @MethodSource("getAllTracksFromTrackLists") public void checkTrackStream(Track track) { + log.trace("Check track stream: {}", track.pretty()); + delayWhenGitHubAction(); + final TrackStream trackStream = assertDoesNotThrow(track::getStream, String.format("Track stream resolving should not throw for: %s", track.getUrl())); @@ -265,6 +285,9 @@ public void checkTrackStream(Track track) { @ParameterizedTest @MethodSource("getAllTracksFromTrackLists") public void refreshTrackInfo(T track) { + log.trace("Refresh track info: {}", track.pretty()); + delayWhenGitHubAction(); + assertDoesNotThrow(() -> trackSearchClient.refreshTrackInfo(track), String.format("Track info refresh should not throw for: %s", track.getUrl())); }