예제 #1
0
 public void ChangeBets(Lottery lottery, int num)
 {
     for (int i = 0; i < num; i++)
     {
         Task.Run(async() =>
         {
             await Task.Delay(Lottery.Rand.Next(100, 1000));
             var name = UserOperations.GetName();
             var user = await UserOperations.RegisterOrLoad(lottery.CasinoTestInstance, $"{name}@karmel.com", name);
             while (true)
             {
                 await Task.Delay(Lottery.Rand.Next(100, 500));
                 await user.PlaceBet(lottery.CasinoTestInstance, lottery.Id, RandomSequence(), Lottery.Rand.Next(1, 10));
             }
         });
     }
 }
예제 #2
0
        public static Task StartPlacingBets(Lottery lottery, int num)
        {
            var tasks = new List <Task>();

            for (int i = 0; i < num; i++)
            {
                var t = Task.Run(async() =>
                {
                    try
                    {
                        await Task.Delay(Lottery.Rand.Next(500, 1000)).ConfigureAwait(false);
                        var name = UserOperations.GetName();
                        var user = await UserOperations.RegisterOrLoad($"{name}@karmel.com", name)
                                   .ConfigureAwait(false);
                        for (int j = 0; j < 10; j++)
                        {
                            await Task.Delay(Lottery.Rand.Next(500, 1000)).ConfigureAwait(false);
                            await user.PlaceBet(lottery.Id, RandomSequence(), Lottery.Rand.Next(1, 10))
                            .ConfigureAwait(false);
                        }
                    }
                    catch (ConcurrencyException)
                    {
                        // expected
                    }
                    catch (InsufficientFunds)
                    {
                        // expected
                    }
                    catch (JavaScriptException e) when(e.Message.Contains("Lottery is over!"))
                    {
                        // expected
                    }
                    catch (Exception e)
                    {
                        // not expected at all!
                        Console.WriteLine(e);
                        throw;
                    }
                });
                tasks.Add(t);
            }

            return(Task.WhenAll(tasks));
        }