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

startWithLoyaltyCardNoExpirySetExpiry test can fail depending on time(zone) #2124

Open
obfusk opened this issue Oct 21, 2024 · 4 comments
Open

Comments

@obfusk
Copy link
Contributor

obfusk commented Oct 21, 2024

I had an odd test failure. Running the tests with TZ=UTC fixed it (it was indeed the 22nd in my time zone but still the 21st in UTC).

org.junit.ComparisonFailure: expected:<October 2[2], 2024> but was:<October 2[1], 2024>
	at org.junit.Assert.assertEquals(Assert.java:117)
	at org.junit.Assert.assertEquals(Assert.java:146)
	at protect.card_locker.LoyaltyCardViewActivityTest.checkFieldProperties(LoyaltyCardViewActivityTest.java:293)
	at protect.card_locker.LoyaltyCardViewActivityTest.checkAllFields(LoyaltyCardViewActivityTest.java:320)
	at protect.card_locker.LoyaltyCardViewActivityTest.startWithLoyaltyCardNoExpirySetExpiry(LoyaltyCardViewActivityTest.java:741)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:569)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.robolectric.RobolectricTestRunner$HelperTestRunner$1.evaluate(RobolectricTestRunner.java:489)
	at org.robolectric.internal.SandboxTestRunner$2.lambda$evaluate$2(SandboxTestRunner.java:291)
	at org.robolectric.internal.bytecode.Sandbox.lambda$runOnMainThread$0(Sandbox.java:104)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:840)
@TheLastProject
Copy link
Member

Every now and then I get an email from someone who says setting an expiry "doesn't work". Most people don't respond when I ask them what "doesn't work" means, one person stated it "sets the wrong day". Sadly even that person didn't further respond when I asked them which day they entered and what they go and what timezone they're in. I've long suspected there was some timezone related issue there but I never had enough info to justify spending a lot of time taking a look so this test failure may actually be showing that issue. Maybe it'll help actually fix whatever is going wrong.

@perepujal
Copy link

In my box, Debian Sid, I can reproduce this problem between 00am and 01am each day
Catalan locale if this matters, timezone Europe Madrid, UTC+1 if I am not wrong

Adding a log in the LoyaltyCardViewActivityTest.java file and running gradlew with the -d option shows the following:
2025-01-04T00:43:22.042+0100 [DEBUG] [TestEventLogger] W/LoyaltyCardViewActivityTesttt.java: checkFieldProperties- contents :January 4, 2025 textView.getEditText().getText().toString():January 3, 2025

Running with TZ=UTC instead passes the test, with the UTC date
2025-01-03T23:47:51.275+0000 [DEBUG] [TestEventLogger] W/LoyaltyCardViewActivityTesttt.java: checkFieldProperties- contents :January 3, 2025 textView.getEditText().getText().toString():January 3, 2025

HTH, let me know what other tests can I make
Pere

@TheLastProject
Copy link
Member

Thanks, that's quite helpful.

How are you forcing the timezone? Perhaps we can add this to the unit tests as a first step and then fix this bug from there? Having correct unit tests is always useful to ensure it gets fixed properly and won't break in the future :)

@perepujal
Copy link

Hi, I am doing this in the command line
TZ=UTC ./gradlew -h build
Seeing that gradlew is a shell script, one could add a line like
export TZ=UTC
but this will only affect builds that use the gradlew script, I have no idea how gradlew.bat or direct builds from gradle or Android Studio could be modified.
Anyway, I imagine the real fix should be in LoyaltyCardViewActivityTest.java

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

No branches or pull requests

3 participants