|
| 1 | +package datadog.trace.civisibility.domain.buildsystem |
| 2 | + |
| 3 | +import datadog.trace.api.Config |
| 4 | +import datadog.trace.api.civisibility.config.EarlyFlakeDetectionSettings |
| 5 | +import datadog.trace.api.civisibility.config.ModuleExecutionSettings |
| 6 | +import datadog.trace.api.civisibility.config.TestIdentifier |
| 7 | +import datadog.trace.api.civisibility.coverage.CoverageDataSupplier |
| 8 | +import datadog.trace.api.civisibility.coverage.CoverageStore |
| 9 | +import datadog.trace.api.civisibility.telemetry.CiVisibilityMetricCollector |
| 10 | +import datadog.trace.civisibility.codeowners.Codeowners |
| 11 | +import datadog.trace.civisibility.decorator.TestDecorator |
| 12 | +import datadog.trace.civisibility.ipc.SignalClient |
| 13 | +import datadog.trace.civisibility.source.MethodLinesResolver |
| 14 | +import datadog.trace.civisibility.source.SourcePathResolver |
| 15 | +import datadog.trace.test.util.DDSpecification |
| 16 | + |
| 17 | +class ProxyTestModuleTest extends DDSpecification { |
| 18 | + |
| 19 | + def "test total retries limit is applied across test cases"() { |
| 20 | + def moduleExecutionSettings = Stub(ModuleExecutionSettings) |
| 21 | + moduleExecutionSettings.getEarlyFlakeDetectionSettings() >> EarlyFlakeDetectionSettings.DEFAULT |
| 22 | + moduleExecutionSettings.isFlakyTestRetriesEnabled() >> true |
| 23 | + moduleExecutionSettings.getFlakyTests(_) >> null |
| 24 | + |
| 25 | + def config = Stub(Config) |
| 26 | + config.getCiVisibilityFlakyRetryCount() >> 2 // this counts all executions of a test case (first attempt is counted too) |
| 27 | + config.getCiVisibilityTotalFlakyRetryCount() >> 2 // this counts retries across all tests (first attempt is not a retry, so it is not counted) |
| 28 | + |
| 29 | + given: |
| 30 | + def proxyTestModule = new ProxyTestModule( |
| 31 | + 1L, |
| 32 | + 1L, |
| 33 | + "test-module", |
| 34 | + moduleExecutionSettings, |
| 35 | + config, |
| 36 | + Stub(CiVisibilityMetricCollector), |
| 37 | + Stub(TestDecorator), |
| 38 | + Stub(SourcePathResolver), |
| 39 | + Stub(Codeowners), |
| 40 | + Stub(MethodLinesResolver), |
| 41 | + Stub(CoverageStore.Factory), |
| 42 | + Stub(CoverageDataSupplier), |
| 43 | + GroovyMock(SignalClient.Factory) |
| 44 | + ) |
| 45 | + |
| 46 | + when: |
| 47 | + def retryPolicy1 = proxyTestModule.retryPolicy(new TestIdentifier("suite", "test-1", null, null)) |
| 48 | + |
| 49 | + then: |
| 50 | + retryPolicy1.retry(false, 1L) // 2nd test execution, 1st retry globally |
| 51 | + !retryPolicy1.retry(false, 1L) // asking for 3rd test execution - local limit reached |
| 52 | + |
| 53 | + when: |
| 54 | + def retryPolicy2 = proxyTestModule.retryPolicy(new TestIdentifier("suite", "test-2", null, null)) |
| 55 | + |
| 56 | + then: |
| 57 | + retryPolicy2.retry(false, 1L) // 2nd test execution, 2nd retry globally (since previous test was retried too) |
| 58 | + !retryPolicy2.retry(false, 1L) // asking for 3rd test execution - local limit reached |
| 59 | + |
| 60 | + when: |
| 61 | + def retryPolicy3 = proxyTestModule.retryPolicy(new TestIdentifier("suite", "test-3", null, null)) |
| 62 | + |
| 63 | + then: |
| 64 | + !retryPolicy3.retry(false, 1L) // asking for 3rd retry globally - global limit reached |
| 65 | + } |
| 66 | +} |
0 commit comments