Skip to content
This repository has been archived by the owner on Jun 12, 2021. It is now read-only.

Commit

Permalink
#25 refactor: simplified timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
adamralph committed Jan 26, 2014
1 parent f22e6cb commit 4609300
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 23 deletions.
1 change: 1 addition & 0 deletions src/Xbehave.Sdk.Net40/Step.cs
Expand Up @@ -23,6 +23,7 @@ public Step(string name, object stepType)
{
this.name = name;
this.stepType = stepType;
this.MillisecondsTimeout = -1;
}

public virtual string Name
Expand Down
13 changes: 3 additions & 10 deletions src/Xbehave.Sdk.Net40/SyncStep.cs
Expand Up @@ -57,17 +57,10 @@ public override void Execute()
}
});

if (this.MillisecondsTimeout > 0)
// NOTE: we do not call the WaitOne(int) overload because it wasn't introduced until .NET 3.5 SP1 and we want to support pre-SP1
if (!@event.WaitOne(this.MillisecondsTimeout, false))
{
// NOTE: we do not call the WaitOne(int) overload because it wasn't introduced until .NET 3.5 SP1 and we want to support pre-SP1
if (!@event.WaitOne(this.MillisecondsTimeout, false))
{
throw new Xunit.Sdk.TimeoutException(this.MillisecondsTimeout);
}
}
else
{
@event.WaitOne();
throw new Xunit.Sdk.TimeoutException(this.MillisecondsTimeout);
}

if (exception != null)
Expand Down
15 changes: 2 additions & 13 deletions src/Xbehave.Sdk.Net45/AsyncStep.cs
Expand Up @@ -24,20 +24,9 @@ public override void Execute()
{
try
{
if (this.MillisecondsTimeout > 0)
if (!this.body().Wait(this.MillisecondsTimeout))
{
var task = this.body();
var timeout = Task.Delay(this.MillisecondsTimeout);
if (Task.WhenAny(task, timeout).Result == timeout)
{
throw new Xunit.Sdk.TimeoutException(this.MillisecondsTimeout);
}

task.Wait();
}
else
{
this.body().Wait();
throw new Xunit.Sdk.TimeoutException(this.MillisecondsTimeout);
}
}
catch (AggregateException ex)
Expand Down

0 comments on commit 4609300

Please sign in to comment.