Skip to content

Commit 3c19d5d

Browse files
authored
- Fix, re-enable delay unit test (#27)
- Clarify that delays are prone to small margins of error in README.md - New setup script for installing .NET versions on Unix
1 parent dd01597 commit 3c19d5d

File tree

4 files changed

+34
-7
lines changed

4 files changed

+34
-7
lines changed

EasyVCR.Tests/ClientTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ public async Task TestDefaultRequestMatching()
101101
}
102102

103103
[TestMethod]
104-
[Ignore] // TODO: fix this test
105104
public async Task TestDelay()
106105
{
107106
var cassette = TestUtils.GetCassette("test_delay");
@@ -122,7 +121,7 @@ public async Task TestDelay()
122121

123122
// confirm the normal replay worked, note time
124123
Assert.IsNotNull(response);
125-
var normalReplayTime = (int)stopwatch.ElapsedMilliseconds;
124+
var normalReplayTime = Math.Max(0, (int)stopwatch.ElapsedMilliseconds); // sometimes stopwatch returns a negative number, let's avoid that
126125

127126
// set up advanced settings
128127
var delay = normalReplayTime + 3000; // add 3 seconds to the normal replay time, for good measure
@@ -139,9 +138,10 @@ public async Task TestDelay()
139138
response = await fakeDataService.GetIPAddressDataRawResponse();
140139
stopwatch.Stop();
141140

142-
// check that the delay was respected
141+
// check that the delay was respected (within margin of error)
143142
Assert.IsNotNull(response);
144-
Assert.IsTrue((int)stopwatch.ElapsedMilliseconds >= delay);
143+
var delay95Percentile = (int)(delay * 0.95); // 5% tolerance
144+
Assert.IsTrue((int)stopwatch.ElapsedMilliseconds >= delay95Percentile);
145145
}
146146

147147
[TestMethod]

Makefile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,14 @@ scan:
9191
dotnet tool run security-scan --verbose --no-banner --ignore-msbuild-errors EasyVCR.sln
9292
# "--ignore-msbuild-errors" needed since MSBuild does not like F#: https://github.com/security-code-scan/security-code-scan/issues/235
9393

94-
## setup - Install required .NET versions and tools (Windows only)
95-
setup:
94+
## setup-win - Install required .NET versions and tools (Windows only)
95+
setup-win:
9696
scripts\setup.bat
9797

98+
## setup-unix - Install required .NET versions and tools (Unix only)
99+
setup-unix:
100+
bash scripts/setup.sh
101+
98102
## sign - Sign all generated DLLs and NuGet packages with the provided certificate (Windows only)
99103
# @parameters:
100104
# cert= - The certificate to use for signing the built assets.
@@ -118,4 +122,4 @@ test-fw:
118122
uninstall-scanner:
119123
dotnet tool uninstall security-scan
120124

121-
.PHONY: help build build-test-fw build-prod clean format install-cert install-tools install lint lint-scripts pre-release publish-all publish release restore scan setup sign test test-fw uninstall-scanner
125+
.PHONY: help build build-test-fw build-prod clean format install-cert install-tools install lint lint-scripts pre-release publish-all publish release restore scan setup-unix setup-win sign test test-fw uninstall-scanner

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ var httpClient = HttpClients.NewHttpClient(cassette, Mode.Record, advancedSettin
8686

8787
Simulate a delay when replaying a recorded request, either using a specified delay or the original request duration.
8888

89+
NOTE: Delays may suffer from a small margin of error on certain .NET versions. Do not rely on the delay being exact down to the millisecond.
90+
8991
**Default**: *No delay*
9092

9193
```csharp

scripts/setup.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
3+
# This script is used to download and install the required .NET versions
4+
5+
# .NET versions we want to install
6+
declare -a NetVersions=("Current" "6.0" "5.0" "3.1")
7+
8+
# Download dotnet-install.sh
9+
echo "Downloading dotnet-install.sh script..."
10+
curl -sSL https://dot.net/v1/dotnet-install.sh -o dotnet-install.sh
11+
12+
# Install each .NET version
13+
echo "Installing .NET versions..."
14+
for version in ${NetVersions[@]}; do
15+
echo "Installing .NET $version..."
16+
sudo bash ./dotnet-install.sh -c "$version"
17+
done
18+
19+
# Remove dotnet-install.sh
20+
echo "Removing dotnet-install.sh script..."
21+
rm dotnet-install.sh

0 commit comments

Comments
 (0)