Skip to content

Commit c6cb20e

Browse files
Introduce "TestEnabled" flag for testing async timeout tests
1 parent b357e86 commit c6cb20e

File tree

6 files changed

+22
-4
lines changed

6 files changed

+22
-4
lines changed

build.proj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
<!-- Flag to control if Windows drivers should be built or not -->
1313
<IsEnabledWindows Condition="'$(IsEnabledWindows)' == '' AND '$(TargetsWindows)' == 'true'">true</IsEnabledWindows>
1414
<IsEnabledWindows Condition="'$(TargetsUnix)' == 'true'">false</IsEnabledWindows>
15+
<TestEnabled Condition="$(TestEnabled) == ''">false</TestEnabled>
1516
<TestOS Condition="'$(TestTargetOS)' == '' AND '$(TargetsWindows)' == 'true'">Windows</TestOS>
1617
<TestOS Condition="'$(TestTargetOS)' == '' AND '$(TargetsUnix)' == 'true'">Unix</TestOS>
1718
<GenerateNuget Condition="'$(GenerateNuget)' == ''">true</GenerateNuget>
18-
<ProjectProperties>Configuration=$(Configuration);AssemblyFileVersion=$(AssemblyFileVersion);TargetsWindows=$(TargetsWindows);TargetsUnix=$(TargetsUnix);</ProjectProperties>
19+
<ProjectProperties>Configuration=$(Configuration);AssemblyFileVersion=$(AssemblyFileVersion);TargetsWindows=$(TargetsWindows);TargetsUnix=$(TargetsUnix);TestEnabled=$(TestEnabled);</ProjectProperties>
1920
<TestProjectProperties>BuildProjectReferences=false;$(ProjectProperties);</TestProjectProperties>
2021
</PropertyGroup>
2122

src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
1212
<TargetGroup Condition="$(TargetFramework.StartsWith('netcoreapp'))">netcoreapp</TargetGroup>
1313
<TargetGroup Condition="$(TargetFramework.StartsWith('netstandard'))">netstandard</TargetGroup>
14+
<DefineConstants Condition="'$(TestEnabled)'=='true'">$(DefineConstants);TEST_ENABLED;</DefineConstants>
1415
<Configurations>Debug;Release;netcoreapp2.1-Debug;netcoreapp2.1-Release;netcoreapp3.1-Debug;netcoreapp3.1-Release</Configurations>
1516
<Platforms>AnyCPU;x64;x86</Platforms>
1617
<IntermediateOutputPath>$(ObjFolder)$(Configuration).$(Platform)\$(AssemblyName)\netcore\</IntermediateOutputPath>

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObject.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,13 @@ public TimeoutState(int value)
136136
internal volatile bool _attentionSent; // true if we sent an Attention to the server
137137
internal volatile bool _attentionSending;
138138

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

145147
private readonly LastIOTimer _lastSuccessfulIOTimer;
146148

@@ -2288,11 +2290,12 @@ public bool IsTimeoutStateExpired
22882290
}
22892291
private void OnTimeoutAsync(object state)
22902292
{
2293+
#if TEST_ENABLED
22912294
if (_enforceTimeoutDelay)
22922295
{
22932296
Thread.Sleep(_enforcedTimeoutDelayInMilliSeconds);
22942297
}
2295-
2298+
#endif
22962299
int currentIdentityValue = _timeoutIdentityValue;
22972300
TimeoutState timeoutState = (TimeoutState)state;
22982301
if (timeoutState.IdentityValue == _timeoutIdentityValue)

src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
We should remove ResolveComReferenceSilent as soon as we can remove the dependency on mscoree. -->
2222
<ResolveComReferenceSilent>True</ResolveComReferenceSilent>
2323
<DefineConstants>$(DefineConstants);NETFRAMEWORK;</DefineConstants>
24+
<DefineConstants Condition="'$(TestEnabled)'=='true'">$(DefineConstants);TEST_ENABLED;</DefineConstants>
2425
</PropertyGroup>
2526
<PropertyGroup>
2627
<TargetFrameworkMonikerAssemblyAttributesPath>$([System.IO.Path]::Combine('$(IntermediateOutputPath)','$(GeneratedSourceFileName)'))</TargetFrameworkMonikerAssemblyAttributesPath>

src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParserStateObject.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,13 @@ internal int ObjectID
129129
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)
130130
internal volatile bool _attentionSending = false;
131131

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

138140
private readonly LastIOTimer _lastSuccessfulIOTimer;
139141

@@ -2373,11 +2375,13 @@ public bool IsTimeoutStateExpired
23732375

23742376
private void OnTimeoutAsync(object state)
23752377
{
2378+
2379+
#if TEST_ENABLED
23762380
if (_enforceTimeoutDelay)
23772381
{
23782382
Thread.Sleep(_enforcedTimeoutDelayInMilliSeconds);
23792383
}
2380-
2384+
#endif
23812385
int currentIdentityValue = _timeoutIdentityValue;
23822386
TimeoutState timeoutState = (TimeoutState)state;
23832387
if (timeoutState.IdentityValue == _timeoutIdentityValue)

src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/AsyncTest/AsyncTimeoutTest.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,15 @@ private static void RunTest(AsyncAPI api, string commonObj, int timeoutDelay, bo
9292
sqlConnection.Open();
9393
if (timeoutDelay != 0)
9494
{
95-
ConnectionHelper.SetEnforcedTimeout(sqlConnection, true, timeoutDelay);
95+
try
96+
{
97+
98+
ConnectionHelper.SetEnforcedTimeout(sqlConnection, true, timeoutDelay);
99+
}
100+
catch
101+
{
102+
Assert.False(true, "Driver does not support explicit timeout delay support. Build all configurations with `/p:TestEnabled=true` property specified.");
103+
}
96104
}
97105
switch (commonObj)
98106
{

0 commit comments

Comments
 (0)