コード例 #1
0
        private async Task AddNewUsers(int usersChanged, ITestExecutionContextInternal context)
        {
            Console.WriteLine("Adding {0} Users", usersChanged);

            for (var i = 0; i < usersChanged; i++)
            {
                var userNum = context.CurrentUsers + 1;

                var httpUser = GetNextHttpUser(userNum);

                await Task.Run(async() =>
                {
                    var user = new User(userNum, httpUser);

                    Console.WriteLine($"Initializing User {userNum}");

                    try
                    {
                        await user.Initialize();
                        context.ModifyUsers(list => list.Add(user));

                        Console.WriteLine($"Added User {userNum}");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine($"Failed initializing User {userNum}");
                        Console.Write(ex);
                        return;
                    }

                    await user.Run(result => UserIterationFinished?.Invoke(result));
                });
            }
        }
コード例 #2
0
        private Task AddNewUsers(int usersChanged, ITestExecutionContextInternal context)
        {
            Console.WriteLine("Adding {0} Users", usersChanged);

            var addUserTasks = new List <Task>();

            for (var i = 0; i < usersChanged; i++)
            {
                var addUserTask = Task.Run(async() =>
                {
                    var userNum = context.UserInitializing();

                    var httpUser = GetNextHttpUser(userNum);

                    var user = new User(userNum, httpUser);

                    Console.WriteLine($"Initializing User {userNum}");

                    try
                    {
                        await user.Initialize();
                        context.UserInitialized(user);

                        Console.WriteLine($"Added User {userNum}");
                    }
                    catch (Exception)
                    {
                        Console.WriteLine($"GAVE UP Trying to initialize User {userNum}");
                        return;
                    }

                    await user.Run(_executionTimestamp.GetElapsedTime, result => UserIterationFinished?.Invoke(result));
                });

                addUserTasks.Add(addUserTask);
            }

            return(Task.WhenAll(addUserTasks));
        }