• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

re-use workmanager instance between multiple unit tests

Hello,

Is there any way i can re-use an existing workmanager for application instances created by multiple tests?.

My issue:
i have multiple unit tests, my first test runs succesfully, next time onwards i face below error.

W/eSync: Can not re-initialize work manager, Robolectric problem?
2021-07-02T19:40:08.323+0530 [DEBUG] [TestEventLogger] java.lang.IllegalStateException: WorkManager is already initialized. Did you try to initialize it manually without disabling WorkManagerInitializer? See WorkManager#initialize(Context, Configuration) or the class level Javadoc for more information.
so can i use re-use an existing workmanager (created during first unit test) for application instances created by multiple tests?

i tried to old work manager instance, that time work manager state is illegalStateException

2021-07-05T10:16:54.668+0530 [DEBUG] [TestEventLogger] java.util.concurrent.ExecutionException: java.lang.IllegalStateException: Illegal connection pointer 1. Current pointers for thread Thread[pool-2-thread-3,5,SDK 28] []
2021-07-05T10:16:54.668+0530 [DEBUG] [TestEventLogger] at androidx.work.impl.utils.futures.AbstractFuture.getDoneValue(AbstractFuture.java:516)
2021-07-05T10:16:54.668+0530 [DEBUG] [TestEventLogger] at androidx.work.impl.utils.futures.AbstractFuture.get(AbstractFuture.java:497)
2021-07-05T10:16:54.668+0530 [DEBUG] [TestEventLogger] at com.excelfore.esync.agent.JoynextUpdateApp.isWorkScheduled(JoynextUpdateApp.java:254)
2021-07-05T10:16:54.668+0530 [DEBUG] [TestEventLogger] at com.excelfore.esync.agent.JoynextUpdateApp.onCreate(JoynextUpdateApp.java:230)
2021-07-05T10:16:54.668+0530 [DEBUG] [TestEventLogger] at org.robolectric.android.internal.AndroidTestEnvironment.lambda$installAndCreateApplication$0(AndroidTestEnvironment.java:288)
2021-07-05T10:16:54.668+0530 [DEBUG] [TestEventLogger] at org.robolectric.util.PerfStatsCollector.measure(PerfStatsCollector.java:75)
2021-07-05T10:16:54.668+0530 [DEBUG] [TestEventLogger] at org.robolectric.android.internal.AndroidTestEnvironment.installAndCreateApplication(AndroidTestEnvironment.java:288)
2021-07-05T10:16:54.668+0530 [DEBUG] [TestEventLogger] at org.robolectric.android.internal.AndroidTestEnvironment.setUpApplicationState(AndroidTestEnvironment.java:171)
2021-07-05T10:16:54.668+0530 [DEBUG] [TestEventLogger] at org.robolectric.RobolectricTestRunner.beforeTest(RobolectricTestRunner.java:319)
2021-07-05T10:16:54.668+0530 [DEBUG] [TestEventLogger] at org.robolectric.internal.SandboxTestRunner$2.lambda$evaluate$0(SandboxTestRunner.java:254)
2021-07-05T10:16:54.669+0530 [DEBUG] [TestEventLogger] at org.robolectric.internal.bytecode.Sandbox.lambda$runOnMainThread$0(Sandbox.java:89)
2021-07-05T10:16:54.669+0530 [DEBUG] [TestEventLogger] at java.util.concurrent.FutureTask.run(FutureTask.java:266)
2021-07-05T10:16:54.669+0530 [DEBUG] [TestEventLogger] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
2021-07-05T10:16:54.669+0530 [DEBUG] [TestEventLogger] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
2021-07-05T10:16:54.669+0530 [DEBUG] [TestEventLogger] at java.lang.Thread.run(Thread.java:748)
2021-07-05T10:16:54.669+0530 [DEBUG] [TestEventLogger] Caused by: java.lang.IllegalStateException: Illegal connection pointer 1. Current pointers for thread Thread[pool-2-thread-3,5,SDK 28] []
2021-07-05T10:16:54.669+0530 [DEBUG] [TestEventLogger] at org.robolectric.shadows.ShadowSQLiteConnection$Connections.getConnection(ShadowSQLiteConnection.java:369)
2021-07-05T10:16:54.669+0530 [DEBUG] [TestEventLogger] at org.robolectric.shadows.ShadowSQLiteConnection$Connections.prepareStatement(ShadowSQLiteConnection.java:419)
2021-07-05T10:16:54.669+0530 [DEBUG] [TestEventLogger] at org.robolectric.shadows.ShadowSQLiteConnection.nativePrepareStatement(ShadowSQLiteConnection.java:90)
2021-07-05T10:16:54.669+0530 [DEBUG] [TestEventLogger] at android.database.sqlite.SQLiteConnection.nativePrepareStatement(SQLiteConnection.java)
2021-07-05T10:16:54.669+0530 [DEBUG] [TestEventLogger] at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:903)
2021-07-05T10:16:54.669+0530 [DEBUG] [TestEventLogger] at android.database.sqlite.SQLiteConnection.execute(SQLiteConnection.java:562)
2021-07-05T10:16:54.669+0530 [DEBUG] [TestEventLogger] at android.database.sqlite.SQLiteSession.beginTransactionUnchecked(SQLiteSession.java:323)
2021-07-05T10:16:54.669+0530 [DEBUG] [TestEventLogger] at android.database.sqlite.SQLiteSession.beginTransaction(SQLiteSession.java:298)
2021-07-05T10:16:54.669+0530 [DEBUG] [TestEventLogger] at android.database.sqlite.SQLiteDatabase.beginTransaction(SQLiteDatabase.java:549)
2021-07-05T10:16:54.669+0530 [DEBUG] [TestEventLogger] at android.database.sqlite.SQLiteDatabase.beginTransaction(SQLiteDatabase.java:460)
2021-07-05T10:16:54.669+0530 [DEBUG] [TestEventLogger] at androidx.sqlite.db.framework.FrameworkSQLiteDatabase.beginTransaction(FrameworkSQLiteDatabase.java:69)
2021-07-05T10:16:54.669+0530 [DEBUG] [TestEventLogger] at androidx.room.RoomDatabase.beginTransaction(RoomDatabase.java:354)
2021-07-05T10:16:54.669+0530 [DEBUG] [TestEventLogger] at androidx.work.impl.model.WorkSpecDao_Impl.getWorkStatusPojoForTag(WorkSpecDao_Impl.java:1033)
2021-07-05T10:16:54.669+0530 [DEBUG] [TestEventLogger] at androidx.work.impl.utils.StatusRunnable$3.runInternal(StatusRunnable.java:130)
2021-07-05T10:16:54.669+0530 [DEBUG] [TestEventLogger] at androidx.work.impl.utils.StatusRunnable$3.runInternal(StatusRunnable.java:125)
2021-07-05T10:16:54.669+0530 [DEBUG] [TestEventLogger] at androidx.work.impl.utils.StatusRunnable.run(StatusRunnable.java:47)
2021-07-05T10:16:54.669+0530 [DEBUG] [TestEventLogger] at androidx.work.impl.utils.SerialExecutor$Task.run(SerialExecutor.java:91)
2021-07-05T10:16:54.669+0530 [DEBUG] [TestEventLogger] ... 3 more


Thanks and Regards,
ck
 
Last edited:
Back
Top Bottom