From 4a7cfd1a6cc63a95140c03a937c9f607303e1a57 Mon Sep 17 00:00:00 2001 From: XiangRongLin <41164160+XiangRongLin@users.noreply.github.com> Date: Tue, 18 Jan 2022 18:36:43 +0100 Subject: [PATCH 1/4] Ensure order of search history entries in tests --- .../newpipe/local/history/HistoryRecordManagerTest.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/src/androidTest/java/org/schabi/newpipe/local/history/HistoryRecordManagerTest.kt b/app/src/androidTest/java/org/schabi/newpipe/local/history/HistoryRecordManagerTest.kt index 15e88b09e..1bac3d101 100644 --- a/app/src/androidTest/java/org/schabi/newpipe/local/history/HistoryRecordManagerTest.kt +++ b/app/src/androidTest/java/org/schabi/newpipe/local/history/HistoryRecordManagerTest.kt @@ -53,11 +53,12 @@ class HistoryRecordManagerTest { @Test fun deleteSearchHistory() { + val now = OffsetDateTime.now() val entries = listOf( - SearchHistoryEntry(OffsetDateTime.now(), 0, "A"), - SearchHistoryEntry(OffsetDateTime.now(), 2, "A"), - SearchHistoryEntry(OffsetDateTime.now(), 1, "B"), - SearchHistoryEntry(OffsetDateTime.now(), 0, "B"), + SearchHistoryEntry(now.minusSeconds(1), 0, "A"), + SearchHistoryEntry(now.minusSeconds(2), 2, "A"), + SearchHistoryEntry(now.minusSeconds(3), 1, "B"), + SearchHistoryEntry(now.minusSeconds(4), 0, "B"), ) // make sure all 4 were inserted From 3c21be8fa5d66383d2fb1b2d4be28d2e409b2929 Mon Sep 17 00:00:00 2001 From: XiangRongLin <41164160+XiangRongLin@users.noreply.github.com> Date: Thu, 20 Jan 2022 19:14:47 +0100 Subject: [PATCH 2/4] use constant instead of now --- .../local/history/HistoryRecordManagerTest.kt | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/app/src/androidTest/java/org/schabi/newpipe/local/history/HistoryRecordManagerTest.kt b/app/src/androidTest/java/org/schabi/newpipe/local/history/HistoryRecordManagerTest.kt index 1bac3d101..f27bddea0 100644 --- a/app/src/androidTest/java/org/schabi/newpipe/local/history/HistoryRecordManagerTest.kt +++ b/app/src/androidTest/java/org/schabi/newpipe/local/history/HistoryRecordManagerTest.kt @@ -12,7 +12,9 @@ import org.schabi.newpipe.database.AppDatabase import org.schabi.newpipe.database.history.model.SearchHistoryEntry import org.schabi.newpipe.testUtil.TestDatabase import org.schabi.newpipe.testUtil.TrampolineSchedulerRule +import java.time.LocalDateTime import java.time.OffsetDateTime +import java.time.ZoneOffset import java.util.concurrent.TimeUnit class HistoryRecordManagerTest { @@ -53,12 +55,11 @@ class HistoryRecordManagerTest { @Test fun deleteSearchHistory() { - val now = OffsetDateTime.now() val entries = listOf( - SearchHistoryEntry(now.minusSeconds(1), 0, "A"), - SearchHistoryEntry(now.minusSeconds(2), 2, "A"), - SearchHistoryEntry(now.minusSeconds(3), 1, "B"), - SearchHistoryEntry(now.minusSeconds(4), 0, "B"), + SearchHistoryEntry(time.minusSeconds(1), 0, "A"), + SearchHistoryEntry(time.minusSeconds(2), 2, "A"), + SearchHistoryEntry(time.minusSeconds(3), 1, "B"), + SearchHistoryEntry(time.minusSeconds(4), 0, "B"), ) // make sure all 4 were inserted @@ -87,9 +88,9 @@ class HistoryRecordManagerTest { @Test fun deleteCompleteSearchHistory() { val entries = listOf( - SearchHistoryEntry(OffsetDateTime.now(), 1, "A"), - SearchHistoryEntry(OffsetDateTime.now(), 2, "B"), - SearchHistoryEntry(OffsetDateTime.now(), 0, "C"), + SearchHistoryEntry(time.minusSeconds(1), 1, "A"), + SearchHistoryEntry(time.minusSeconds(2), 2, "B"), + SearchHistoryEntry(time.minusSeconds(3), 0, "C"), ) // make sure all 3 were inserted @@ -143,14 +144,16 @@ class HistoryRecordManagerTest { } companion object { - val RELATED_SEARCHES_ENTRIES = listOf( - SearchHistoryEntry(OffsetDateTime.now().minusSeconds(7), 2, "AC"), - SearchHistoryEntry(OffsetDateTime.now().minusSeconds(6), 0, "ABC"), - SearchHistoryEntry(OffsetDateTime.now().minusSeconds(5), 1, "BA"), - SearchHistoryEntry(OffsetDateTime.now().minusSeconds(4), 3, "A"), - SearchHistoryEntry(OffsetDateTime.now().minusSeconds(2), 0, "B"), - SearchHistoryEntry(OffsetDateTime.now().minusSeconds(3), 2, "AA"), - SearchHistoryEntry(OffsetDateTime.now().minusSeconds(1), 1, "A"), + private val time = OffsetDateTime.of(LocalDateTime.of(2000, 1, 1, 1, 1), ZoneOffset.UTC) + + private val RELATED_SEARCHES_ENTRIES = listOf( + SearchHistoryEntry(time.minusSeconds(7), 2, "AC"), + SearchHistoryEntry(time.minusSeconds(6), 0, "ABC"), + SearchHistoryEntry(time.minusSeconds(5), 1, "BA"), + SearchHistoryEntry(time.minusSeconds(4), 3, "A"), + SearchHistoryEntry(time.minusSeconds(2), 0, "B"), + SearchHistoryEntry(time.minusSeconds(3), 2, "AA"), + SearchHistoryEntry(time.minusSeconds(1), 1, "A"), ) } } From a6515d5450d4eac4b85b9644ea3dfa9d7140a49c Mon Sep 17 00:00:00 2001 From: litetex <40789489+litetex@users.noreply.github.com> Date: Fri, 21 Jan 2022 22:15:34 +0100 Subject: [PATCH 3/4] Moved timeout control from the tests to the CI pipeline How fast a tests is executed on a shared CI pipeline is not predictable as the build might be throttled because other builds are running. Therefore adding extremely short timeouts inside the tests - where they can't be changed - is a bad idea. Removed them for now. --- .github/workflows/ci.yml | 1 + .../schabi/newpipe/local/history/HistoryRecordManagerTest.kt | 3 --- .../schabi/newpipe/local/playlist/LocalPlaylistManagerTest.kt | 3 --- 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6bf49a98a..49e78e997 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -52,6 +52,7 @@ jobs: test-android: # macos has hardware acceleration. See android-emulator-runner action runs-on: macos-latest + timeout-minutes: 20 strategy: matrix: # api-level 19 is min sdk, but throws errors related to desugaring diff --git a/app/src/androidTest/java/org/schabi/newpipe/local/history/HistoryRecordManagerTest.kt b/app/src/androidTest/java/org/schabi/newpipe/local/history/HistoryRecordManagerTest.kt index f27bddea0..cfb2efcb6 100644 --- a/app/src/androidTest/java/org/schabi/newpipe/local/history/HistoryRecordManagerTest.kt +++ b/app/src/androidTest/java/org/schabi/newpipe/local/history/HistoryRecordManagerTest.kt @@ -25,9 +25,6 @@ class HistoryRecordManagerTest { @get:Rule val trampolineScheduler = TrampolineSchedulerRule() - @get:Rule - val timeout = Timeout(1, TimeUnit.SECONDS) - @Before fun setup() { database = TestDatabase.createReplacingNewPipeDatabase() diff --git a/app/src/androidTest/java/org/schabi/newpipe/local/playlist/LocalPlaylistManagerTest.kt b/app/src/androidTest/java/org/schabi/newpipe/local/playlist/LocalPlaylistManagerTest.kt index 249492d8f..ef7609604 100644 --- a/app/src/androidTest/java/org/schabi/newpipe/local/playlist/LocalPlaylistManagerTest.kt +++ b/app/src/androidTest/java/org/schabi/newpipe/local/playlist/LocalPlaylistManagerTest.kt @@ -20,9 +20,6 @@ class LocalPlaylistManagerTest { @get:Rule val trampolineScheduler = TrampolineSchedulerRule() - @get:Rule - val timeout = Timeout(1, TimeUnit.SECONDS) - @Before fun setup() { database = TestDatabase.createReplacingNewPipeDatabase() From 3d3d94655be767994f6d9bb5caca8c9f964781fc Mon Sep 17 00:00:00 2001 From: litetex <40789489+litetex@users.noreply.github.com> Date: Fri, 21 Jan 2022 22:19:52 +0100 Subject: [PATCH 4/4] Fixed imports --- .../schabi/newpipe/local/history/HistoryRecordManagerTest.kt | 2 -- .../schabi/newpipe/local/playlist/LocalPlaylistManagerTest.kt | 2 -- 2 files changed, 4 deletions(-) diff --git a/app/src/androidTest/java/org/schabi/newpipe/local/history/HistoryRecordManagerTest.kt b/app/src/androidTest/java/org/schabi/newpipe/local/history/HistoryRecordManagerTest.kt index cfb2efcb6..c32a43b2a 100644 --- a/app/src/androidTest/java/org/schabi/newpipe/local/history/HistoryRecordManagerTest.kt +++ b/app/src/androidTest/java/org/schabi/newpipe/local/history/HistoryRecordManagerTest.kt @@ -7,7 +7,6 @@ import org.junit.Assert.assertEquals import org.junit.Before import org.junit.Rule import org.junit.Test -import org.junit.rules.Timeout import org.schabi.newpipe.database.AppDatabase import org.schabi.newpipe.database.history.model.SearchHistoryEntry import org.schabi.newpipe.testUtil.TestDatabase @@ -15,7 +14,6 @@ import org.schabi.newpipe.testUtil.TrampolineSchedulerRule import java.time.LocalDateTime import java.time.OffsetDateTime import java.time.ZoneOffset -import java.util.concurrent.TimeUnit class HistoryRecordManagerTest { diff --git a/app/src/androidTest/java/org/schabi/newpipe/local/playlist/LocalPlaylistManagerTest.kt b/app/src/androidTest/java/org/schabi/newpipe/local/playlist/LocalPlaylistManagerTest.kt index ef7609604..c392d8d3d 100644 --- a/app/src/androidTest/java/org/schabi/newpipe/local/playlist/LocalPlaylistManagerTest.kt +++ b/app/src/androidTest/java/org/schabi/newpipe/local/playlist/LocalPlaylistManagerTest.kt @@ -4,13 +4,11 @@ import org.junit.After import org.junit.Before import org.junit.Rule import org.junit.Test -import org.junit.rules.Timeout import org.schabi.newpipe.database.AppDatabase import org.schabi.newpipe.database.stream.model.StreamEntity import org.schabi.newpipe.extractor.stream.StreamType import org.schabi.newpipe.testUtil.TestDatabase import org.schabi.newpipe.testUtil.TrampolineSchedulerRule -import java.util.concurrent.TimeUnit class LocalPlaylistManagerTest {