Repository navigation
test(kates): the tests that stub a mock a scheduled job also calls run with the scheduler off, so the job cannot take the stub - #385
Merged
Conversation
…n with the scheduler off, so the job cannot take the stub AdvisorResourceTest.analyzeReturns404ForMissingRun failed on CI (PR #376) with "WrongTypeOfReturnValue: Optional cannot be returned by findByStatus()". Mockito ties when(mock.call()).thenReturn(...) to the last call made on that mock, from any thread. The timeout reaper calls findByStatus on the mocked TestRunRepository every 60 s; when that call lands between the test's findById and its thenReturn, the stub goes to findByStatus. doReturn().when() has the same window. Each of the five classes stubs a mock that a job calls: - AdvisorResourceTest, ReportResourceTest: TestRunRepository, called by TestTimeoutReaper.reapStuckTests (findByStatus). - ScheduleResourceTest: ScheduledTestRunRepository, called by TestScheduler.evaluateSchedules (findAllEnabled); TrogdorClient, called by the run reconciler for the runs the test starts. - TestResourceTest: TrogdorClient, called by TestOrchestrator.reconcileActiveRuns for the runs the test starts. - TrendServiceTest: ClusterHealthService, called by KafkaReachabilityCache.refresh (isReachable). None of them needs a job to fire: they read runs over GET, which refreshes the run itself. SchedulerOffTestProfile sets quarkus.scheduler.enabled=false and the five classes use it. Every other test keeps the scheduler as before.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
AdvisorResourceTest.analyzeReturns404ForMissingRunfailed on PR #376 (run 39062142823, attempt 1) withWrongTypeOfReturnValue: Optional cannot be returned by findByStatus(). When you writewhen(mock.call()).thenReturn(...), Mockito attaches the stub to the most recent call on that mock, whichever thread made it. Every 60 s the timeout reaper callsfindByStatuson the mockedTestRunRepository. If that call happens between the test'sfindByIdand itsthenReturn, the stub lands onfindByStatus.doReturn().when()has the same gap.In each of the five classes, the test stubs a mock that a scheduled job also calls:
What
SchedulerOffTestProfile, which setsquarkus.scheduler.enabled=false.Tests
findByStatuswhile the main thread stubbedfindById../mvnw -o test: 1466 tests, 0 failures.spotless:checkpasses.go test ./cmd -run TestMCPCaveatpasses.