@@ -9,7 +9,8 @@ namespace BenchmarkDotNet.Tests.Engine
9
9
{
10
10
public class EngineFactoryTests
11
11
{
12
- int timesBenchmarkCalled = 0 , timesGlobalSetupCalled = 0 , timesGlobalCleanupCalled = 0 , timesIterationSetupCalled = 0 , timesIterationCleanupCalled = 0 ;
12
+ int timesBenchmarkCalled = 0 , timesIdleCalled = 0 ;
13
+ int timesGlobalSetupCalled = 0 , timesGlobalCleanupCalled = 0 , timesIterationSetupCalled = 0 , timesIterationCleanupCalled = 0 ;
13
14
14
15
void GlobalSetup ( ) => timesGlobalSetupCalled ++ ;
15
16
void IterationSetup ( ) => timesIterationSetupCalled ++ ;
@@ -25,19 +26,22 @@ void VeryTimeConsumingSingle(long _)
25
26
}
26
27
27
28
void InstantSingle ( long _ ) => timesBenchmarkCalled ++ ;
28
-
29
29
void Instant16 ( long _ ) => timesBenchmarkCalled += 16 ;
30
+
31
+ void IdleSingle ( long _ ) => timesIdleCalled ++ ;
32
+ void Idle16 ( long _ ) => timesIdleCalled += 16 ;
30
33
31
34
[ Fact ]
32
35
public void VeryTimeConsumingBenchmarksAreExecutedOncePerIterationForDefaultSettings ( )
33
36
{
34
- var engineParameters = CreateEngineParameters ( singleAction : VeryTimeConsumingSingle , multiAction : Throwing , job : Job . Default ) ;
37
+ var engineParameters = CreateEngineParameters ( mainSingleAction : VeryTimeConsumingSingle , mainMultiAction : Throwing , job : Job . Default ) ;
35
38
36
39
var engine = new EngineFactory ( ) . CreateReadyToRun ( engineParameters ) ;
37
40
38
41
Assert . Equal ( 1 , timesGlobalSetupCalled ) ;
39
42
Assert . Equal ( 1 , timesIterationSetupCalled ) ;
40
43
Assert . Equal ( 1 , timesBenchmarkCalled ) ;
44
+ Assert . Equal ( 1 , timesIdleCalled ) ;
41
45
Assert . Equal ( 1 , timesIterationCleanupCalled ) ;
42
46
Assert . Equal ( 0 , timesGlobalCleanupCalled ) ; // cleanup is called as part of dispode
43
47
@@ -52,13 +56,14 @@ public void VeryTimeConsumingBenchmarksAreExecutedOncePerIterationForDefaultSett
52
56
[ Fact ]
53
57
public void ForJobsThatDontRequireJittingOnlyGlobalSetupIsCalled ( )
54
58
{
55
- var engineParameters = CreateEngineParameters ( singleAction : Throwing , multiAction : Throwing , job : Job . Dry ) ;
59
+ var engineParameters = CreateEngineParameters ( mainSingleAction : Throwing , mainMultiAction : Throwing , job : Job . Dry ) ;
56
60
57
61
var engine = new EngineFactory ( ) . CreateReadyToRun ( engineParameters ) ;
58
62
59
63
Assert . Equal ( 1 , timesGlobalSetupCalled ) ;
60
64
Assert . Equal ( 0 , timesIterationSetupCalled ) ;
61
65
Assert . Equal ( 0 , timesBenchmarkCalled ) ;
66
+ Assert . Equal ( 0 , timesIdleCalled ) ;
62
67
Assert . Equal ( 0 , timesIterationCleanupCalled ) ;
63
68
Assert . Equal ( 0 , timesGlobalCleanupCalled ) ;
64
69
@@ -70,13 +75,14 @@ public void ForJobsThatDontRequireJittingOnlyGlobalSetupIsCalled()
70
75
[ Fact ]
71
76
public void NonVeryTimeConsumingBenchmarksAreExecutedMoreThanOncePerIterationWithUnrollFactorForDefaultSettings ( )
72
77
{
73
- var engineParameters = CreateEngineParameters ( singleAction : InstantSingle , multiAction : Instant16 , job : Job . Default ) ;
78
+ var engineParameters = CreateEngineParameters ( mainSingleAction : InstantSingle , mainMultiAction : Instant16 , job : Job . Default ) ;
74
79
75
80
var engine = new EngineFactory ( ) . CreateReadyToRun ( engineParameters ) ;
76
81
77
82
Assert . Equal ( 1 , timesGlobalSetupCalled ) ;
78
83
Assert . Equal ( 2 , timesIterationSetupCalled ) ; // once for single and & once for 16
79
84
Assert . Equal ( 1 + 16 , timesBenchmarkCalled ) ;
85
+ Assert . Equal ( 1 + 16 , timesIdleCalled ) ;
80
86
Assert . Equal ( 2 , timesIterationCleanupCalled ) ; // once for single and & once for 16
81
87
Assert . Equal ( 0 , timesGlobalCleanupCalled ) ;
82
88
@@ -87,7 +93,7 @@ public void NonVeryTimeConsumingBenchmarksAreExecutedMoreThanOncePerIterationWit
87
93
Assert . Equal ( 1 , timesGlobalCleanupCalled ) ;
88
94
}
89
95
90
- private EngineParameters CreateEngineParameters ( Action < long > singleAction , Action < long > multiAction , Job job )
96
+ private EngineParameters CreateEngineParameters ( Action < long > mainSingleAction , Action < long > mainMultiAction , Job job )
91
97
=> new EngineParameters
92
98
{
93
99
Dummy1Action = ( ) => { } ,
@@ -96,13 +102,12 @@ private EngineParameters CreateEngineParameters(Action<long> singleAction, Actio
96
102
GlobalSetupAction = GlobalSetup ,
97
103
GlobalCleanupAction = GlobalCleanup ,
98
104
Host = new ConsoleHost ( TextWriter . Null , TextReader . Null ) ,
99
- IdleMultiAction = _ => { } ,
100
- IdleSingleAction = _ => { } ,
105
+ IdleMultiAction = Idle16 ,
106
+ IdleSingleAction = IdleSingle ,
101
107
IterationCleanupAction = IterationCleanup ,
102
108
IterationSetupAction = IterationSetup ,
103
- MainMultiAction = multiAction ,
104
- MainSingleAction = singleAction ,
105
- Resolver = EngineResolver . Instance ,
109
+ MainMultiAction = mainMultiAction ,
110
+ MainSingleAction = mainSingleAction ,
106
111
TargetJob = job
107
112
} ;
108
113
}
0 commit comments