Browse files

Concurrency tests Updated for multiple users

  • Loading branch information...
1 parent b5e2465 commit 3a50404eb75cb72200b95876fac30b80ce1a6d1b hernandl committed May 9, 2012
View
14 ...es/Registration/Individual Reservation/SelfRegistrationReservationWithConcurrency.feature
@@ -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
View
22 ...Registration/Individual Reservation/SelfRegistrationReservationWithConcurrency.feature.cs
@@ -77,7 +77,7 @@ public virtual void FeatureBackground()
table1.AddRow(new string[] {
"CQRS Workshop",
"$500",
- "1"});
+ "10"});
#line 21
testRunner.Given("the list of the available Order Items for the CQRS summit 2012 conference", ((string)(null)), table1);
#line hidden
@@ -111,7 +111,7 @@ public virtual void OnlyOneOrderItemIsAvailableAndTwoRegistrantsTryToReserveItTh
"quantity"});
table2.AddRow(new string[] {
"CQRS Workshop",
- "1"});
+ "6"});
#line 26
testRunner.Given("the selected Order Items", ((string)(null)), table2);
#line hidden
@@ -120,7 +120,7 @@ public virtual void OnlyOneOrderItemIsAvailableAndTwoRegistrantsTryToReserveItTh
"quantity"});
table3.AddRow(new string[] {
"CQRS Workshop",
- "1"});
+ "6"});
#line 29
testRunner.And("another Registrant selects these Order Items", ((string)(null)), table3);
#line 32
@@ -136,7 +136,7 @@ public virtual void OnlyOneOrderItemIsAvailableAndTwoRegistrantsTryToReserveItTh
"message"});
table4.AddRow(new string[] {
"CQRS Workshop",
- "0",
+ "4",
"Could not reserve all the requested seats."});
#line 35
testRunner.And("a second Reservation is offered to select any of these available seats", ((string)(null)), table4);
@@ -147,12 +147,12 @@ public virtual void OnlyOneOrderItemIsAvailableAndTwoRegistrantsTryToReserveItTh
[Xunit.FactAttribute()]
[Xunit.TraitAttribute("FeatureTitle", "Self-Registrant scenarios for making a Reservation for a Conference site where tw" +
"o Registrants make simultaneous reservations")]
- [Xunit.TraitAttribute("Description", "Only one Order Item is available and two Registrants try to reserve it at the sam" +
- "e time, then only one get the reservation")]
- public virtual void OnlyOneOrderItemIsAvailableAndTwoRegistrantsTryToReserveItAtTheSameTimeThenOnlyOneGetTheReservation()
+ [Xunit.TraitAttribute("Description", "Only one Order Item is available and many Registrants try to reserve it, then onl" +
+ "y one get the reservation")]
+ public virtual void OnlyOneOrderItemIsAvailableAndManyRegistrantsTryToReserveItThenOnlyOneGetTheReservation()
{
- TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Only one Order Item is available and two Registrants try to reserve it at the sam" +
- "e time, then only one get the reservation", new string[] {
+ TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Only one Order Item is available and many Registrants try to reserve it, then onl" +
+ "y one get the reservation", new string[] {
"NoWatiN"});
#line 41
this.ScenarioSetup(scenarioInfo);
@@ -166,9 +166,9 @@ public virtual void OnlyOneOrderItemIsAvailableAndTwoRegistrantsTryToReserveItAt
"CQRS Workshop",
"1"});
#line 42
- testRunner.When("two Registrants selects these Order Items", ((string)(null)), table5);
+ testRunner.When("20 Registrants selects these Order Items", ((string)(null)), table5);
#line 45
- testRunner.Then("only one Registrant is confirmed for all the selected Order Items");
+ testRunner.Then("only 10 Registrants get confirmed reservations for the selected Order Items");
#line hidden
this.ScenarioCleanup();
}
View
3 source/Conference.AcceptanceTests/Conference.Specflow/Steps/Registration/CommonSteps.cs
@@ -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")]
View
8 ...Conference.Specflow/Steps/Registration/SelfRegistrationEndToEndWithInfrastructureSteps.cs
@@ -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 =
View
42 ...Conference.Specflow/Steps/Registration/SelfRegistrationReservationWithConcurrencySteps.cs
@@ -12,6 +12,7 @@
// ==============================================================================================================
using System;
+using System.Linq;
using System.Threading.Tasks;
using Conference.Specflow.Support;
using TechTalk.SpecFlow;
@@ -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);
}
}
}
View
4 ...rence.Specflow/Steps/Registration/SelfRegistrationReservationWithFullAvailabilitySteps.cs
@@ -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");

0 comments on commit 3a50404

Please sign in to comment.