Skip to content

Commit

Permalink
Fix iteration cleanup bug (#1231)
Browse files Browse the repository at this point in the history
* fix iteration cleanup bug
  • Loading branch information
adamsitnik authored Aug 23, 2019
1 parent b6d0e0f commit bc9624c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private static EngineParameters CreateEngineParameters<T>(
GlobalSetupAction = CallbackFromField(instance, GlobalSetupActionFieldName),
GlobalCleanupAction = CallbackFromField(instance, GlobalCleanupActionFieldName),
IterationSetupAction = CallbackFromField(instance, IterationSetupActionFieldName),
IterationCleanupAction = CallbackFromField(instance, IterationSetupActionFieldName),
IterationCleanupAction = CallbackFromField(instance, IterationCleanupActionFieldName),
TargetJob = benchmarkCase.Job,
OperationsPerInvoke = benchmarkCase.Descriptor.OperationsPerInvoke,
MeasureExtraStats = benchmarkCase.Config.HasExtraStatsDiagnoser(),
Expand Down
31 changes: 31 additions & 0 deletions tests/BenchmarkDotNet.IntegrationTests/InProcessEmitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,5 +221,36 @@ public static ValueTask<decimal> InvokeOnceStaticValueTaskOfT()
return new ValueTask<decimal>(DecimalResult);
}
}

[Fact]
public void InProcessEmitToolchainSupportsIterationSetupAndCleanup()
{
var logger = new OutputLogger(Output);
var config = CreateInProcessConfig(logger);

WithIterationSetupAndCleanup.SetupCounter = 0;
WithIterationSetupAndCleanup.BenchmarkCounter = 0;
WithIterationSetupAndCleanup.CleanupCounter = 0;

var summary = CanExecute<WithIterationSetupAndCleanup>(config);

Assert.Equal(1, WithIterationSetupAndCleanup.SetupCounter);
Assert.Equal(16, WithIterationSetupAndCleanup.BenchmarkCounter);
Assert.Equal(1, WithIterationSetupAndCleanup.CleanupCounter);
}

public class WithIterationSetupAndCleanup
{
public static int SetupCounter, BenchmarkCounter, CleanupCounter;

[IterationSetup]
public void Setup() => Interlocked.Increment(ref SetupCounter);

[Benchmark]
public void Benchmark() => Interlocked.Increment(ref BenchmarkCounter);

[IterationCleanup]
public void Cleanup() => Interlocked.Increment(ref CleanupCounter);
}
}
}

0 comments on commit bc9624c

Please sign in to comment.