cashapp / paparazzi

Render your Android screens without a physical device or emulator
https://cashapp.github.io/paparazzi/
Apache License 2.0
2.24k stars 212 forks source link

Snapshotting fails if `Dispatchers.setMain` and `Dispatchers.resetMain` have been called #1304

Closed ansman closed 5 months ago

ansman commented 5 months ago

Description We're seeing random failures using the latest paparazzi version due to another test setting the main dispatcher.

Steps to Reproduce Here is an example test that showcase the issue:

class ExampleTest {
    init {
        // This is actually happening in another test class that happens to run before this test
        // Commenting out these two lines makes the test pass
        Dispatchers.setMain(UnconfinedTestDispatcher())
        Dispatchers.resetMain()
    }

    @get:Rule
    val paparazzi = Paparazzi()

    @Test
    fun test() {
        paparazzi.snapshot { Box(Modifier.size(10.dp).background(Color.Red)) }
    }
}

Expected behavior Paparazzi should be able to record regardless of if main has previously been changed.

Additional information:

TWiStErRob commented 5 months ago

Duplicate of https://github.com/cashapp/paparazzi/issues/1198 ?

ansman commented 5 months ago

Duplicate of #1198 ?

Probably same root cause if I had to guess but it’s a different problem (I’m getting exceptions during paparazzi tests). I’ll let someone else decide if they want to merge the tickets or not

TWiStErRob commented 5 months ago

You might be right, I misread the version numbers.

Anyway, the solution might be similar: can you please check if 1.3.3-SNAPSHOT makes a difference? There have been a lot of changes since 1.3.2.

kevinsunhg commented 3 months ago

is this issue indeed fixed? we are on 1.3.3 and still seeing random failures without manually setting main dispatcher

cpaleop commented 3 months ago

We too see failures with 1.3.2 and 1.3.3 and we are setting/resetting the main dispatcher in hundreds of tests. Can we please revisit? cc @gamepro65 @jrodbx

gamepro65 commented 3 months ago

The exception thrown in this issue has been fixed since we no longer use Dispatchers.Main.

What specifically are you seeing? Please open a new issue with the failure + any repro / implementation specifics and I can revisit.

cpaleop commented 3 months ago

False alarm, I forgot to apply again the Guava workaround since we skipped version 1.3.2. My bad folks 🤦🏻‍♂️