Skip to content

Commit cf8c023

Browse files
SteSingerStephan Singer
andauthored
33196 command timeout allow zero (#33198)
* Allow zero for WithCommandTimeout. Tests to check that WithCommandTimeout allows zero and rejects negative values * Allow zero for WithCommandTimeout. Tests to check that WithCommandTimeout allows zero and rejects negative values Fixes #33196 --------- Co-authored-by: Stephan Singer <[email protected]>
1 parent 52f37b3 commit cf8c023

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/EFCore.Relational/Infrastructure/RelationalOptionsExtension.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public virtual int? CommandTimeout
162162
/// <returns>A new instance with the option changed.</returns>
163163
public virtual RelationalOptionsExtension WithCommandTimeout(int? commandTimeout)
164164
{
165-
if (commandTimeout is <= 0)
165+
if (commandTimeout is < 0)
166166
{
167167
throw new InvalidOperationException(RelationalStrings.InvalidCommandTimeout(commandTimeout));
168168
}

test/EFCore.Relational.Tests/RelationalConnectionTest.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,26 @@ public void Can_create_new_connection_with_CommandTimeout()
888888
Assert.Equal(99, connection.CommandTimeout);
889889
}
890890

891+
[ConditionalFact]
892+
public void Can_create_new_connection_with_CommandTimeout_set_to_zero()
893+
{
894+
using var connection = new FakeRelationalConnection(
895+
CreateOptions(
896+
new FakeRelationalOptionsExtension()
897+
.WithConnectionString("Database=FrodoLives")
898+
.WithCommandTimeout(0)));
899+
Assert.Equal(0, connection.CommandTimeout);
900+
}
901+
902+
[ConditionalFact]
903+
public void Throws_if_create_new_connection_with_CommandTimeout_negative()
904+
{
905+
Assert.Throws<InvalidOperationException>(
906+
() => new FakeRelationalOptionsExtension()
907+
.WithConnectionString("Database=FrodoLives")
908+
.WithCommandTimeout(-1));
909+
}
910+
891911
[ConditionalFact]
892912
public void Can_set_CommandTimeout()
893913
{
@@ -898,6 +918,16 @@ public void Can_set_CommandTimeout()
898918
Assert.Equal(88, connection.CommandTimeout);
899919
}
900920

921+
[ConditionalFact]
922+
public void Can_set_CommandTimeout_to_zero()
923+
{
924+
using var connection = new FakeRelationalConnection(
925+
CreateOptions(new FakeRelationalOptionsExtension().WithConnectionString("Database=FrodoLives")));
926+
connection.CommandTimeout = 0;
927+
928+
Assert.Equal(0, connection.CommandTimeout);
929+
}
930+
901931
[ConditionalFact]
902932
public void Throws_if_CommandTimeout_out_of_range()
903933
{

0 commit comments

Comments
 (0)