Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Android test as jvm test: TabDataRepository, and fix flaky test #5316

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

cmonfortep
Copy link
Contributor

Task/Issue URL: https://app.asana.com/0/1202552961248957/1208839731155341/f

Description

Fixes flaky test due time reference.
Moves it as jvm.

Steps to test this PR

Feature 1

  • CI is green
  • [ ]

UI changes

Before After
!(Upload before screenshot) (Upload after screenshot)

@cmonfortep
Copy link
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@cmonfortep cmonfortep requested a review from 0nko November 25, 2024 23:02
@0nko 0nko self-assigned this Nov 26, 2024
@@ -468,7 +485,7 @@ class TabDataRepositoryTest {
@Test
fun getActiveTabCountReturnsCorrectCountWhenTabsYoungerThanSpecifiedDay() = runTest {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@0nko after fixing the flaky test, this one is now failing. Can you evaluate the expected result?

Copy link
Member

@0nko 0nko Nov 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fake DateTime provider revealed the timing issue, which made it pass even though it shouldn’t, nice! 👍 It’s not this test that’s failing, it’s getInactiveTabCountReturnsCorrectCountWhenAllTabsOlderThanSpecifiedDay() below (see my comment).

@@ -199,7 +199,7 @@ class TabDataRepository @Inject constructor(
}

override fun countTabsAccessedWithinRange(accessOlderThan: Long, accessNotMoreThan: Long?): Int {
val now = LocalDateTime.now(ZoneOffset.UTC)
val now = timeProvider.localDateTimeNow()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@0nko please review this change, moving to use an injected TimeProvider.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That’s fine, but to save the last access time, we specify the UTC timezone by default. We should update it there, as well, to be consistent.

Copy link
Member

@0nko 0nko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @cmonfortep! I left a couple of comments in the code to fix the failing test and one more thing.

@@ -199,7 +199,7 @@ class TabDataRepository @Inject constructor(
}

override fun countTabsAccessedWithinRange(accessOlderThan: Long, accessNotMoreThan: Long?): Int {
val now = LocalDateTime.now(ZoneOffset.UTC)
val now = timeProvider.localDateTimeNow()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That’s fine, but to save the last access time, we specify the UTC timezone by default. We should update it there, as well, to be consistent.

@@ -468,7 +485,7 @@ class TabDataRepositoryTest {
@Test
fun getActiveTabCountReturnsCorrectCountWhenTabsYoungerThanSpecifiedDay() = runTest {
Copy link
Member

@0nko 0nko Nov 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fake DateTime provider revealed the timing issue, which made it pass even though it shouldn’t, nice! 👍 It’s not this test that’s failing, it’s getInactiveTabCountReturnsCorrectCountWhenAllTabsOlderThanSpecifiedDay() below (see my comment).

@@ -497,7 +514,7 @@ class TabDataRepositoryTest {
@Test
fun getInactiveTabCountReturnsCorrectCountWhenAllTabsOlderThanSpecifiedDay() = runTest {
// Arrange: Add some tabs with different last access times
val now = LocalDateTime.now(ZoneOffset.UTC)
val now = now()
val tab1 = TabEntity(tabId = "tab1", lastAccessTime = now.minusDays(8))
val tab2 = TabEntity(tabId = "tab2", lastAccessTime = now.minusDays(10))
val tab3 = TabEntity(tabId = "tab3", lastAccessTime = now.minusDays(9))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix

Suggested change
val tab3 = TabEntity(tabId = "tab3", lastAccessTime = now.minusDays(9))
val tab3 = TabEntity(tabId = "tab3", lastAccessTime = now.minusDays(9).minusSeconds(1))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants