@@ -23,6 +23,7 @@ import org.mockito.kotlin.inOrder
2323import org.mockito.kotlin.isNull
2424import org.mockito.kotlin.mock
2525import org.mockito.kotlin.spy
26+ import org.mockito.kotlin.times
2627import org.mockito.kotlin.verify
2728import org.mockito.kotlin.verifyBlocking
2829import org.mockito.kotlin.whenever
@@ -646,4 +647,28 @@ class LightningRepoTest : BaseUnitTest() {
646647 assertTrue(result.isSuccess)
647648 verify(lightningService).setup(any(), anyOrNull(), anyOrNull(), isNull(), anyOrNull())
648649 }
650+
651+ @Test
652+ fun `start should not retry when node lifecycle state is Running` () = test {
653+ sut.setInitNodeLifecycleState()
654+ whenever(lightningService.node).thenReturn(null )
655+ whenever(lightningService.setup(any(), anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull())).thenReturn(Unit )
656+ whenever(settingsStore.data).thenReturn(flowOf(SettingsData ()))
657+ val blocktank = mock<BlocktankService >()
658+ whenever(coreService.blocktank).thenReturn(blocktank)
659+ whenever(blocktank.info(any())).thenReturn(null )
660+
661+ // lightningService.start() succeeds (state becomes Running at line 241)
662+ whenever(lightningService.start(anyOrNull(), any())).thenReturn(Unit )
663+ // lightningService.nodeId throws during syncState() (called at line 244, AFTER state = Running)
664+ whenever(lightningService.nodeId).thenThrow(RuntimeException (" error during syncState" ))
665+
666+ val result = sut.start()
667+
668+ // Defensive check: state is Running, so don't retry, return success
669+ assertTrue(result.isSuccess)
670+ assertEquals(NodeLifecycleState .Running , sut.lightningState.value.nodeLifecycleState)
671+ // Verify start was only called once (no retry)
672+ verify(lightningService, times(1 )).start(anyOrNull(), any())
673+ }
649674}
0 commit comments