Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix iteration cleanup bug #1231

Merged
merged 2 commits into from
Aug 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
}