@@ -29,6 +29,7 @@ import com.cosmotech.run.config.existTable
29
29
import com.cosmotech.run.config.toDataTableName
30
30
import com.cosmotech.run.domain.Run
31
31
import com.cosmotech.run.domain.RunDataQuery
32
+ import com.cosmotech.run.domain.RunStatus
32
33
import com.cosmotech.run.domain.SendRunDataRequest
33
34
import com.cosmotech.run.workflow.WorkflowService
34
35
import com.cosmotech.runner.RunnerApiServiceInterface
@@ -66,19 +67,22 @@ import org.json.JSONObject
66
67
import org.junit.jupiter.api.BeforeEach
67
68
import org.junit.jupiter.api.Nested
68
69
import org.junit.jupiter.api.Test
70
+ import org.junit.jupiter.api.assertDoesNotThrow
69
71
import org.junit.jupiter.api.assertThrows
70
72
import org.junit.jupiter.api.extension.ExtendWith
71
73
import org.junit.runner.RunWith
72
74
import org.postgresql.util.PSQLException
73
75
import org.slf4j.LoggerFactory
74
76
import org.springframework.beans.factory.annotation.Autowired
75
77
import org.springframework.boot.test.context.SpringBootTest
78
+ import org.springframework.http.HttpStatus
76
79
import org.springframework.jdbc.core.JdbcTemplate
77
80
import org.springframework.jdbc.datasource.DriverManagerDataSource
78
81
import org.springframework.test.context.ActiveProfiles
79
82
import org.springframework.test.context.junit.jupiter.SpringExtension
80
83
import org.springframework.test.context.junit4.SpringRunner
81
84
import org.springframework.test.util.ReflectionTestUtils
85
+ import org.springframework.web.client.RestClientResponseException
82
86
83
87
@ActiveProfiles(profiles = [" run-test" ])
84
88
@ExtendWith(MockKExtension ::class )
@@ -104,7 +108,8 @@ class RunServiceIntegrationTest : CsmRunTestBase() {
104
108
@Autowired lateinit var solutionApiService: SolutionApiServiceInterface
105
109
@Autowired lateinit var workspaceApiService: WorkspaceApiServiceInterface
106
110
@SpykBean @Autowired lateinit var runnerApiService: RunnerApiServiceInterface
107
- @Autowired lateinit var runApiService: RunApiServiceInterface
111
+ @SpykBean @Autowired lateinit var runServiceImpl: RunServiceImpl
112
+ @SpykBean @Autowired lateinit var runApiService: RunApiServiceInterface
108
113
@Autowired lateinit var eventPublisher: com.cosmotech.api.events.CsmEventPublisher
109
114
110
115
@Autowired lateinit var adminRunStorageTemplate: JdbcTemplate
@@ -397,6 +402,83 @@ class RunServiceIntegrationTest : CsmRunTestBase() {
397
402
}
398
403
}
399
404
405
+ @Test
406
+ fun `test get running logs` () {
407
+ runSavedId =
408
+ mockStartRun(organizationSaved.id, workspaceSaved.id, runnerSaved.id, solutionSaved.id)
409
+ val run = mockk<Run >()
410
+ every { runApiService.getRun(any(), any(), any(), any()) } returns run
411
+ every { run.id } returns " id"
412
+ every { runServiceImpl.getRunStatus(any(), any(), any(), any()) } returns
413
+ RunStatus (endTime = null )
414
+ every { workflowService.getRunningLogs(any()) } returns
415
+ " first line of result" + " |second line of result" + " |third line of result"
416
+ every { workflowService.getArchivedLogs(any()) } throws Exception ()
417
+
418
+ assertEquals(
419
+ " first line of result" + " |second line of result" + " |third line of result" ,
420
+ runApiService.getRunLogs(
421
+ organizationSaved.id, workspaceSaved.id, runnerSaved.id, runSavedId))
422
+ }
423
+
424
+ @Test
425
+ fun `test get archived logs` () {
426
+ runSavedId =
427
+ mockStartRun(organizationSaved.id, workspaceSaved.id, runnerSaved.id, solutionSaved.id)
428
+ val run = mockk<Run >()
429
+ every { runApiService.getRun(any(), any(), any(), any()) } returns run
430
+ every { run.id } returns " id"
431
+ every { runServiceImpl.getRunStatus(any(), any(), any(), any()) } returns
432
+ RunStatus (endTime = " endTime" )
433
+ logger.info(" should get archived logs" )
434
+ every { workflowService.getRunningLogs(any()) } throws
435
+ RestClientResponseException (" message" , HttpStatus .NOT_FOUND , " statusTest" , null , null , null )
436
+ every { workflowService.getArchivedLogs(any()) } returns
437
+ " first line of result" + " |second line of result" + " |third line of result"
438
+ assertEquals(
439
+ " first line of result" + " |second line of result" + " |third line of result" ,
440
+ runApiService.getRunLogs(
441
+ organizationSaved.id, workspaceSaved.id, runnerSaved.id, runSavedId))
442
+ }
443
+
444
+ @Test
445
+ fun `test should get archived logs after a status change` () {
446
+ runSavedId =
447
+ mockStartRun(organizationSaved.id, workspaceSaved.id, runnerSaved.id, solutionSaved.id)
448
+ val run = mockk<Run >()
449
+ every { runApiService.getRun(any(), any(), any(), any()) } returns run
450
+ every { run.id } returns " id"
451
+ every { runServiceImpl.getRunStatus(any(), any(), any(), any()) } returns
452
+ RunStatus (endTime = null )
453
+ logger.info(" should get logs even with a status change after assertion" )
454
+ every { workflowService.getRunningLogs(any()) } throws
455
+ RestClientResponseException (" message" , HttpStatus .NOT_FOUND , " statusTest" , null , null , null )
456
+ every { workflowService.getArchivedLogs(any()) } returns
457
+ " first line of result" + " |second line of result" + " |third line of result"
458
+ assertDoesNotThrow {
459
+ runApiService.getRunLogs(organizationSaved.id, workspaceSaved.id, runnerSaved.id, runSavedId)
460
+ }
461
+ assertEquals(
462
+ " first line of result" + " |second line of result" + " |third line of result" ,
463
+ runApiService.getRunLogs(
464
+ organizationSaved.id, workspaceSaved.id, runnerSaved.id, runSavedId))
465
+ }
466
+
467
+ @Test
468
+ fun `test should fail after exception other than not_found` () {
469
+ runSavedId =
470
+ mockStartRun(organizationSaved.id, workspaceSaved.id, runnerSaved.id, solutionSaved.id)
471
+ val run = mockk<Run >()
472
+ every { runApiService.getRun(any(), any(), any(), any()) } returns run
473
+ every { runServiceImpl.getRunStatus(any(), any(), any(), any()) } returns
474
+ RunStatus (endTime = null )
475
+ logger.info(" should throw an error outside of status change error" )
476
+ every { workflowService.getRunningLogs(any()) } throws Exception ()
477
+ assertThrows<Exception > {
478
+ runApiService.getRunLogs(organizationSaved.id, workspaceSaved.id, runnerSaved.id, runSavedId)
479
+ }
480
+ }
481
+
400
482
@Nested
401
483
inner class RunServicePostgresIntegrationTest {
402
484
0 commit comments