Skip to content

Commit

Permalink
Concurrency tests Updated for multiple users
Browse files Browse the repository at this point in the history
  • Loading branch information
hernandl committed May 9, 2012
1 parent b5e2465 commit 3a50404
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 39 deletions.
Expand Up @@ -20,26 +20,26 @@ Feature: Self-Registrant scenarios for making a Reservation for a Conference sit
Background:
Given the list of the available Order Items for the CQRS summit 2012 conference
| seat type | rate | quota |
| CQRS Workshop | $500 | 1 |
| CQRS Workshop | $500 | 10 |

Scenario: Only one Order Item is available and two Registrants try to reserve it, then only one get the reservation
Given the selected Order Items
| seat type | quantity |
| CQRS Workshop | 1 |
| CQRS Workshop | 6 |
And another Registrant selects these Order Items
| seat type | quantity |
| CQRS Workshop | 1 |
| CQRS Workshop | 6 |
When the Registrant proceed to make the Reservation
And another Registrant proceed to make the Reservation with seats already reserved
Then the Reservation is confirmed for all the selected Order Items
And a second Reservation is offered to select any of these available seats
| seat type | selected | message |
| CQRS Workshop | 0 | Could not reserve all the requested seats. |
| CQRS Workshop | 4 | Could not reserve all the requested seats. |


@NoWatiN
Scenario: Only one Order Item is available and two Registrants try to reserve it at the same time, then only one get the reservation
When two Registrants selects these Order Items
Scenario: Only one Order Item is available and many Registrants try to reserve it, then only one get the reservation
When 20 Registrants selects these Order Items
| seat type | quantity |
| CQRS Workshop | 1 |
Then only one Registrant is confirmed for all the selected Order Items
Then only 10 Registrants get confirmed reservations for the selected Order Items

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -61,6 +61,9 @@ public void GivenTheRegistrantEnterTheseDetails(Table table)
browser.SetInput("LastName", table.Rows[0]["last name"]);
browser.SetInput("Email", table.Rows[0]["email address"]);
browser.SetInput("data-val-required", table.Rows[0]["email address"], "Please confirm the e-mail address.");

// Store email in case is needed for later use (Find Order by Code + email access)
ScenarioContext.Current.Set(table.Rows[0]["email address"], "email");
}

[Given(@"these Seat Types becomes unavailable before the Registrant make the reservation")]
Expand Down
Expand Up @@ -150,8 +150,14 @@ public void ThenTheRegistrantAssignTheseSeats(Table table)
{
using (var orderController = RegistrationHelper.GetOrderController())
{
var pricedOrder = RegistrationHelper.GetModel<PricedOrder>(orderController.Display(draftOrder.OrderId));
PricedOrder pricedOrder = null;
var timeout = DateTime.Now.Add(Constants.UI.WaitTimeout);
while((pricedOrder == null || !pricedOrder.AssignmentsId.HasValue) && DateTime.Now < timeout)
{
pricedOrder = RegistrationHelper.GetModel<PricedOrder>(orderController.Display(draftOrder.OrderId));
}

Assert.NotNull(pricedOrder);
Assert.True(pricedOrder.AssignmentsId.HasValue);

var orderSeats =
Expand Down
Expand Up @@ -12,6 +12,7 @@
// ==============================================================================================================

using System;
using System.Linq;
using System.Threading.Tasks;
using Conference.Specflow.Support;
using TechTalk.SpecFlow;
Expand Down Expand Up @@ -59,33 +60,38 @@ public void WhenAnotherRegistrantProceedToMakeTheReservationWithSeatsAlreadyRese
[Binding]
public class SelfRegistrationReservationWithConcurrencyAndInfrastructureSteps
{
private bool onlyOneReserved;
private int confirmed;

[When(@"two Registrants selects these Order Items")]
public void WhenTwoRegistrantsSelectsTheseOrderItems(Table table)
[When(@"(.*) Registrants selects these Order Items")]
public void WhenManyRegistrantsSelectsTheseOrderItems(int registrants, Table table)
{
using (var firstRegistrant = new SelfRegistrationEndToEndWithInfrastructureSteps())
using (var secondRegistrant = new SelfRegistrationEndToEndWithInfrastructureSteps())
Action worker = () =>
{
firstRegistrant.GivenTheSelectedOrderItems(table);
secondRegistrant.GivenTheSelectedOrderItems(table);
try
using (var registrant = new SelfRegistrationEndToEndWithInfrastructureSteps())
{
Parallel.Invoke(firstRegistrant.GivenTheRegistrantProceedToMakeTheReservation,
secondRegistrant.GivenTheRegistrantProceedToMakeTheReservation);
}
catch (AggregateException ae)
{
ae.Handle(e => e is FalseException);
onlyOneReserved = true;
registrant.GivenTheSelectedOrderItems(table);
registrant.GivenTheRegistrantProceedToMakeTheReservation();
}
};

var tasks = Enumerable.Range(0, registrants).Select(i => Task.Factory.StartNew(worker)).ToArray();

try
{
Task.WaitAll(tasks);
}
catch (AggregateException ae)
{
ae.Handle(e => e is FalseException);
}

confirmed = tasks.Count(t => t.IsCompleted && !t.IsFaulted);
}

[Then(@"only one Registrant is confirmed for all the selected Order Items")]
public void ThenOnlyOneRegistrantIsConfirmedForAllTheSelectedOrderItems()
[Then(@"only (.*) Registrants get confirmed reservations for the selected Order Items")]
public void ThenOnlySomeRegistrantsGetConfirmedReservationsForTheSelectedOrderItems(int registrants)
{
Assert.True(onlyOneReserved);
Assert.Equal(registrants, confirmed);
}
}
}
Expand Up @@ -28,11 +28,11 @@ public void ThenTheOrderShouldBeFoundWithTheFollowingOrderItems(Table table)
var browser = ScenarioContext.Current.Browser();
string accessCode = browser.FindText(new Regex("[A-Z0-9]{6}"));
Assert.False(string.IsNullOrWhiteSpace(accessCode));
string email;
Assert.True(ScenarioContext.Current.TryGetValue("email", out email));

Thread.Sleep(Constants.WaitTimeout); // Wait for event processing

var email = ScenarioContext.Current.Get<string>("email");

// Navigate to Registration page
browser.GoTo(Constants.FindOrderPage(ScenarioContext.Current.Get<ConferenceInfo>().Slug));
browser.SetInput("name", email, "email");
Expand Down

0 comments on commit 3a50404

Please sign in to comment.