Skip to content

Commit 19e3a82

Browse files
dtillmanTim Hess
authored andcommitted
Hystrix tests updates (#98)
* Reset more things in more places when performing resets in Hystrix * Limit dotnet test to a single CPU, un-skip the "FlakyOnHostedAgents" test category * Make tests less sensitive to available CPU resources
1 parent 07d519e commit 19e3a82

61 files changed

Lines changed: 2454 additions & 2233 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

azure-pipelines.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
inputs:
4848
command: test
4949
projects: '**/*.Test/*.csproj'
50-
arguments: '-c $(buildConfiguration) --filter "Category!=SkipOnLinux&Category!=FlakyOnHostedAgents"'
50+
arguments: '-c $(buildConfiguration) -maxcpucount:1 --filter "Category!=SkipOnLinux"'
5151
- job: MacOS_Build_and_Test
5252
pool:
5353
vmImage: 'macOS-10.14'
@@ -76,7 +76,7 @@ jobs:
7676
inputs:
7777
command: test
7878
projects: '**/*.Test/*.csproj'
79-
arguments: '-c $(buildConfiguration) --filter "Category!=SkipOnMacOS&Category!=FlakyOnHostedAgents"'
79+
arguments: '-c $(buildConfiguration) -maxcpucount:1 --filter "Category!=SkipOnMacOS"'
8080
- job: Windows_Build_Test_and_Package
8181
pool:
8282
vmImage: 'windows-2019'
@@ -130,7 +130,8 @@ jobs:
130130
inputs:
131131
command: test
132132
projects: 'src/Steeltoe.All.sln'
133-
arguments: '-c $(buildConfiguration) /p:TreatWarningsAsErrors=True /p:CopyLocalLockFileAssemblies=true --filter "Category!=Integration&Category!=FlakyOnHostedAgents" /p:CollectCoverage=true /p:CoverletOutputFormat="opencover" /p:Include="[Steeltoe.*]*" /p:Exclude="[*.Test]*"'
133+
# arguments: '-c $(buildConfiguration) /p:TreatWarningsAsErrors=True /p:CopyLocalLockFileAssemblies=true --filter "Category!=Integration&Category!=FlakyOnHostedAgents" /p:CollectCoverage=true /p:CoverletOutputFormat="opencover" /p:Include="[Steeltoe.*]*" /p:Exclude="[*.Test]*"'
134+
arguments: '-c $(buildConfiguration) -maxcpucount:1 /p:TreatWarningsAsErrors=True /p:CopyLocalLockFileAssemblies=true --filter "Category!=Integration" /p:CollectCoverage=true /p:CoverletOutputFormat="opencover" /p:Include="[Steeltoe.*]*" /p:Exclude="[*.Test]*"'
134135
# Generate the report using ReportGenerator (https://github.com/danielpalme/ReportGenerator)
135136
# First install the tool on the machine, then run it
136137
- pwsh: |
@@ -174,4 +175,4 @@ jobs:
174175
PathtoPublish: $(Build.ArtifactStagingDirectory)
175176
ArtifactName: Packages
176177
publishLocation: Container
177-
condition: always()
178+
condition: always()

src/CircuitBreaker/src/HystrixBase/HystrixCollapserMetrics.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ public static ICollection<HystrixCollapserMetrics> GetInstances()
6767

6868
internal static void Reset()
6969
{
70+
RollingCollapserEventCounterStream.Reset();
71+
CumulativeCollapserEventCounterStream.Reset();
72+
RollingCollapserBatchSizeDistributionStream.Reset();
7073
Metrics.Clear();
7174
}
7275

src/CircuitBreaker/src/HystrixBase/HystrixCommandMetrics.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ internal static void Reset()
117117
metricsInstance.UnsubscribeAll();
118118
}
119119

120+
RollingCommandEventCounterStream.Reset();
121+
CumulativeCommandEventCounterStream.Reset();
122+
RollingCommandLatencyDistributionStream.Reset();
123+
RollingCommandUserLatencyDistributionStream.Reset();
124+
RollingCommandMaxConcurrencyStream.Reset();
125+
HystrixThreadEventStream.Reset();
126+
HealthCountsStream.Reset();
127+
120128
Metrics.Clear();
121129
}
122130

src/CircuitBreaker/src/HystrixBase/HystrixThreadPoolMetrics.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ private static bool HasExecutedCommandsOnThread(HystrixThreadPoolMetrics threadP
9090

9191
internal static void Reset()
9292
{
93+
RollingThreadPoolEventCounterStream.Reset();
94+
CumulativeThreadPoolEventCounterStream.Reset();
95+
RollingThreadPoolMaxConcurrencyStream.Reset();
96+
9397
Metrics.Clear();
9498
}
9599

src/CircuitBreaker/src/HystrixBase/Metric/CachedValuesHistogram.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,5 +150,10 @@ public long GetTotalCount()
150150
{
151151
return totalCount;
152152
}
153+
154+
public override string ToString()
155+
{
156+
return "[Mean: " + GetMean() + "/Total: " + GetTotalCount() + "]";
157+
}
153158
}
154159
}

src/CircuitBreaker/src/HystrixBase/Metric/Consumer/BucketedCounterStream.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using System;
1717
using System.Collections.Generic;
1818
using System.Linq;
19+
using System.Reactive.Concurrency;
1920
using System.Reactive.Linq;
2021

2122
namespace Steeltoe.CircuitBreaker.Hystrix.Metric.Consumer
@@ -50,7 +51,7 @@ protected BucketedCounterStream(IHystrixEventStream<Event> inputEventStream, int
5051
{
5152
return inputEventStream
5253
.Observe()
53-
.Window(TimeSpan.FromMilliseconds(bucketSizeInMs)) // bucket it by the counter window so we can emit to the next operator in time chunks, not on every OnNext
54+
.Window(TimeSpan.FromMilliseconds(bucketSizeInMs), NewThreadScheduler.Default) // bucket it by the counter window so we can emit to the next operator in time chunks, not on every OnNext
5455
.SelectMany((b) =>
5556
{
5657
return reduceBucketToSummary(b);

src/CircuitBreaker/src/HystrixBase/Metric/Consumer/BucketedCumulativeCounterStream.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ public Output Latest
6868
{
6969
get
7070
{
71-
StartCachingStreamValuesIfUnstarted();
7271
if (counterSubject.TryGetValue(out Output v))
7372
{
7473
return v;

src/CircuitBreaker/src/HystrixBase/Metric/Consumer/BucketedRollingCounterStream.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ public Output Latest
9090
{
9191
get
9292
{
93-
StartCachingStreamValuesIfUnstarted();
9493
if (counterSubject.TryGetValue(out Output v))
9594
{
9695
return v;

src/CircuitBreaker/src/HystrixBase/Metric/Consumer/CumulativeCollapserEventCounterStream.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,22 @@ public static CumulativeCollapserEventCounterStream GetInstance(IHystrixCollapse
3535

3636
public static CumulativeCollapserEventCounterStream GetInstance(IHystrixCollapserKey collapserKey, int numBuckets, int bucketSizeInMs)
3737
{
38-
return Streams.GetOrAddEx(collapserKey.Name, (k) => new CumulativeCollapserEventCounterStream(collapserKey, numBuckets, bucketSizeInMs, HystrixCollapserMetrics.AppendEventToBucket, HystrixCollapserMetrics.BucketAggregator));
38+
return Streams.GetOrAddEx(collapserKey.Name, (k) =>
39+
{
40+
var stream = new CumulativeCollapserEventCounterStream(collapserKey, numBuckets, bucketSizeInMs, HystrixCollapserMetrics.AppendEventToBucket, HystrixCollapserMetrics.BucketAggregator);
41+
stream.StartCachingStreamValuesIfUnstarted();
42+
return stream;
43+
});
3944
}
4045

4146
public static void Reset()
4247
{
48+
foreach (var stream in Streams.Values)
49+
{
50+
stream.Unsubscribe();
51+
}
52+
53+
HystrixCollapserEventStream.Reset();
4354
Streams.Clear();
4455
}
4556

src/CircuitBreaker/src/HystrixBase/Metric/Consumer/CumulativeCommandEventCounterStream.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,24 @@ public static CumulativeCommandEventCounterStream GetInstance(IHystrixCommandKey
3535

3636
public static CumulativeCommandEventCounterStream GetInstance(IHystrixCommandKey commandKey, int numBuckets, int bucketSizeInMs)
3737
{
38-
var result = Streams.GetOrAddEx(commandKey.Name, (k) => new CumulativeCommandEventCounterStream(commandKey, numBuckets, bucketSizeInMs, HystrixCommandMetrics.AppendEventToBucket, HystrixCommandMetrics.BucketAggregator));
38+
var result = Streams.GetOrAddEx(commandKey.Name, (k) =>
39+
{
40+
var stream = new CumulativeCommandEventCounterStream(commandKey, numBuckets, bucketSizeInMs, HystrixCommandMetrics.AppendEventToBucket, HystrixCommandMetrics.BucketAggregator);
41+
stream.StartCachingStreamValuesIfUnstarted();
42+
return stream;
43+
});
3944
return result;
4045
}
4146

4247
public static void Reset()
4348
{
49+
foreach (var stream in Streams.Values)
50+
{
51+
stream.Unsubscribe();
52+
}
53+
54+
HystrixCommandCompletionStream.Reset();
55+
4456
Streams.Clear();
4557
}
4658

0 commit comments

Comments
 (0)