17
17
18
18
import org .gradle .api .GradleException ;
19
19
import org .gradle .api .testing .TestOrchestrator ;
20
+ import org .gradle .api .testing .fabric .TestMethodProcessResultStates ;
20
21
import org .gradle .api .testing .execution .PipelineConfig ;
22
+ import org .gradle .api .testing .execution .fork .policies .local .single .LocalSimpleForkPolicyConfig ;
23
+ import org .gradle .api .testing .execution .control .refork .ReforkItemConfigs ;
24
+ import org .gradle .api .testing .execution .control .refork .ReforkReasons ;
25
+ import org .gradle .api .testing .execution .control .refork .ReforkReasonRegister ;
26
+ import org .gradle .api .testing .execution .control .refork .AmountOfTestsExecutedByForkConfig ;
21
27
import org .gradle .api .testing .reporting .ReportConfig ;
22
28
import org .gradle .api .testing .reporting .policies .ReportPolicyNames ;
23
29
import org .gradle .api .testing .reporting .policies .ReportPolicyRegister ;
30
+ import org .gradle .api .testing .reporting .policies .console .ConsoleReportPolicyConfig ;
24
31
import org .gradle .util .GUtil ;
25
32
import org .slf4j .Logger ;
26
33
import org .slf4j .LoggerFactory ;
34
41
public class NativeTest extends AbstractTestTask {
35
42
private static final Logger logger = LoggerFactory .getLogger (NativeTest .class );
36
43
37
- private long reforkEvery = Long . MAX_VALUE ;
44
+ private long reforkEvery = - 1 ;
38
45
39
46
private PipelineConfig defaultPipelineConfig ;
40
47
private Map <String , PipelineConfig > pipelineConfigs ;
41
- private ReportConfig errorsToConsoleReport ;
48
+ private ReportConfig consoleReport ;
42
49
private Map <String , ReportConfig > reportConfigs ;
43
50
44
51
private int maximumNumberOfForks = 4 ;
@@ -49,21 +56,42 @@ public NativeTest() {
49
56
50
57
// default pipeline
51
58
defaultPipelineConfig = new PipelineConfig ("default" );
59
+ ((LocalSimpleForkPolicyConfig )defaultPipelineConfig .getForkPolicyConfig ()).setAmountToStart (4 );
52
60
53
61
pipelineConfigs .put (defaultPipelineConfig .getName (), defaultPipelineConfig );
54
62
55
63
reportConfigs = new HashMap <String , ReportConfig >();
56
64
57
65
// by default we report errors and failures to the console
58
- errorsToConsoleReport = new ReportConfig ("errorsToConsole" );
59
- errorsToConsoleReport .setPolicyConfig (ReportPolicyRegister .getReportPolicy (ReportPolicyNames .ERRORS_TO_CONSOLE ).createReportPolicyConfigInstance ());
66
+ consoleReport = new ReportConfig ("console" );
67
+ consoleReport .setPolicyConfig (ReportPolicyRegister .getReportPolicy (ReportPolicyNames .CONSOLE ).createReportPolicyConfigInstance ());
68
+ final ConsoleReportPolicyConfig reportPolicyConfig = (ConsoleReportPolicyConfig ) consoleReport .getPolicyConfig ();
69
+ reportPolicyConfig .addShowStates (TestMethodProcessResultStates .values ()); // add all
60
70
61
- reportConfigs .put (errorsToConsoleReport .getName (), errorsToConsoleReport );
71
+ reportConfigs .put (consoleReport .getName (), consoleReport );
62
72
63
- defaultPipelineConfig .getReports ().add (errorsToConsoleReport );
73
+ defaultPipelineConfig .getReports ().add (consoleReport );
64
74
}
65
75
66
76
public void executeTests () {
77
+ if ( reforkEvery > 0 ) {
78
+ final ReforkItemConfigs reforkItemConfigs = new ReforkItemConfigs ();
79
+
80
+ final AmountOfTestsExecutedByForkConfig reforkEveryConfig = (AmountOfTestsExecutedByForkConfig ) ReforkReasonRegister .getDecisionContextItem (
81
+ ReforkReasons .AMOUNT_OF_TEST_EXECUTED_BY_FORK
82
+ ).getConfig ();
83
+
84
+ reforkEveryConfig .setReforkEvery (reforkEvery );
85
+
86
+ reforkItemConfigs .addItemConfig (
87
+ ReforkReasons .AMOUNT_OF_TEST_EXECUTED_BY_FORK ,
88
+ reforkEveryConfig
89
+ );
90
+
91
+ defaultPipelineConfig .setReforkItemConfigs (reforkItemConfigs );
92
+ }
93
+
94
+
67
95
final TestOrchestrator orchestrator = new TestOrchestrator (this );
68
96
69
97
orchestrator .execute ();
0 commit comments