Skip to content

Commit

Permalink
Introduce "TestEnabled" flag for testing async timeout tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cheenamalhotra committed Feb 17, 2021
1 parent b357e86 commit 4e4a7f8
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 4 deletions.
5 changes: 5 additions & 0 deletions BUILDGUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ Once the environment is setup properly, execute the desired set of commands belo
# Builds the driver in 'Release' Configuration.
```

```bash
> msbuild /p:Configuration=Release /p:TestEnabled=true
# Builds the driver in 'Release' Configuration with explicit code changes enabled for testing.
```

```bash
> msbuild /p:Platform=Win32
# Builds the .NET Framework (NetFx) driver for Win32 (x86) platform on Windows.
Expand Down
3 changes: 2 additions & 1 deletion build.proj
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
<!-- Flag to control if Windows drivers should be built or not -->
<IsEnabledWindows Condition="'$(IsEnabledWindows)' == '' AND '$(TargetsWindows)' == 'true'">true</IsEnabledWindows>
<IsEnabledWindows Condition="'$(TargetsUnix)' == 'true'">false</IsEnabledWindows>
<TestEnabled Condition="$(TestEnabled) == ''">false</TestEnabled>
<TestOS Condition="'$(TestTargetOS)' == '' AND '$(TargetsWindows)' == 'true'">Windows</TestOS>
<TestOS Condition="'$(TestTargetOS)' == '' AND '$(TargetsUnix)' == 'true'">Unix</TestOS>
<GenerateNuget Condition="'$(GenerateNuget)' == ''">true</GenerateNuget>
<ProjectProperties>Configuration=$(Configuration);AssemblyFileVersion=$(AssemblyFileVersion);TargetsWindows=$(TargetsWindows);TargetsUnix=$(TargetsUnix);</ProjectProperties>
<ProjectProperties>Configuration=$(Configuration);AssemblyFileVersion=$(AssemblyFileVersion);TargetsWindows=$(TargetsWindows);TargetsUnix=$(TargetsUnix);TestEnabled=$(TestEnabled);</ProjectProperties>
<TestProjectProperties>BuildProjectReferences=false;$(ProjectProperties);</TestProjectProperties>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<TargetGroup Condition="$(TargetFramework.StartsWith('netcoreapp'))">netcoreapp</TargetGroup>
<TargetGroup Condition="$(TargetFramework.StartsWith('netstandard'))">netstandard</TargetGroup>
<DefineConstants Condition="'$(TestEnabled)'=='true'">$(DefineConstants);TEST_ENABLED;</DefineConstants>
<Configurations>Debug;Release;netcoreapp2.1-Debug;netcoreapp2.1-Release;netcoreapp3.1-Debug;netcoreapp3.1-Release</Configurations>
<Platforms>AnyCPU;x64;x86</Platforms>
<IntermediateOutputPath>$(ObjFolder)$(Configuration).$(Platform)\$(AssemblyName)\netcore\</IntermediateOutputPath>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,13 @@ public TimeoutState(int value)
internal volatile bool _attentionSent; // true if we sent an Attention to the server
internal volatile bool _attentionSending;

#if TEST_ENABLED
// Below 2 properties are used to enforce timeout delays in code to
// reproduce issues related to theadpool starvation and timeout delay.
// It should always be set to false by default, and only be enabled during testing.
internal bool _enforceTimeoutDelay = false;
internal int _enforcedTimeoutDelayInMilliSeconds = 5000;
#endif

private readonly LastIOTimer _lastSuccessfulIOTimer;

Expand Down Expand Up @@ -2288,11 +2290,12 @@ public bool IsTimeoutStateExpired
}
private void OnTimeoutAsync(object state)
{
#if TEST_ENABLED
if (_enforceTimeoutDelay)
{
Thread.Sleep(_enforcedTimeoutDelayInMilliSeconds);
}

#endif
int currentIdentityValue = _timeoutIdentityValue;
TimeoutState timeoutState = (TimeoutState)state;
if (timeoutState.IdentityValue == _timeoutIdentityValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
We should remove ResolveComReferenceSilent as soon as we can remove the dependency on mscoree. -->
<ResolveComReferenceSilent>True</ResolveComReferenceSilent>
<DefineConstants>$(DefineConstants);NETFRAMEWORK;</DefineConstants>
<DefineConstants Condition="'$(TestEnabled)'=='true'">$(DefineConstants);TEST_ENABLED;</DefineConstants>
</PropertyGroup>
<PropertyGroup>
<TargetFrameworkMonikerAssemblyAttributesPath>$([System.IO.Path]::Combine('$(IntermediateOutputPath)','$(GeneratedSourceFileName)'))</TargetFrameworkMonikerAssemblyAttributesPath>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,13 @@ internal int ObjectID
internal bool _attentionReceived = false; // NOTE: Received is not volatile as it is only ever accessed\modified by TryRun its callees (i.e. single threaded access)
internal volatile bool _attentionSending = false;

#if TEST_ENABLED
// Below 2 properties are used to enforce timeout delays in code to
// reproduce issues related to theadpool starvation and timeout delay.
// It should always be set to false by default, and only be enabled during testing.
internal bool _enforceTimeoutDelay = false;
internal int _enforcedTimeoutDelayInMilliSeconds = 5000;
#endif

private readonly LastIOTimer _lastSuccessfulIOTimer;

Expand Down Expand Up @@ -2373,11 +2375,13 @@ public bool IsTimeoutStateExpired

private void OnTimeoutAsync(object state)
{

#if TEST_ENABLED
if (_enforceTimeoutDelay)
{
Thread.Sleep(_enforcedTimeoutDelayInMilliSeconds);
}

#endif
int currentIdentityValue = _timeoutIdentityValue;
TimeoutState timeoutState = (TimeoutState)state;
if (timeoutState.IdentityValue == _timeoutIdentityValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,15 @@ private static void RunTest(AsyncAPI api, string commonObj, int timeoutDelay, bo
sqlConnection.Open();
if (timeoutDelay != 0)
{
ConnectionHelper.SetEnforcedTimeout(sqlConnection, true, timeoutDelay);
try
{

ConnectionHelper.SetEnforcedTimeout(sqlConnection, true, timeoutDelay);
}
catch
{
Assert.False(true, "Driver does not support explicit timeout delay support. Build all configurations with `/p:TestEnabled=true` property specified.");
}
}
switch (commonObj)
{
Expand Down

0 comments on commit 4e4a7f8

Please sign in to comment.