Esempio n. 1
0
        public async Task TestConcurrentAccountRequestsAsync()
        {
            var logger      = new MockLogger();
            var cosmosState = new MockCosmosState(logger);

            var client = new MockImageGalleryClient(cosmosState, logger);
            await client.InitializeCosmosDbAsync();

            // Try create a new account, and wait for it to be created before proceeding with the test.
            var account = new Account("0", "alice", "*****@*****.**");

            var result = await client.CreateAccountAsync(account);

            Assert.IsTrue(result);

            var updatedAccount = new Account("0", "alice", "*****@*****.**");

            // Try update the account and delete it concurrently, which can cause a data race and a bug.
            var updateTask = client.UpdateAccountAsync(updatedAccount);
            var deleteTask = client.DeleteAccountAsync(updatedAccount.Id);

            // Wait for the two concurrent requests to complete.
            await Task.WhenAll(updateTask, deleteTask);

            // Bug: the update request can nondeterministically fail due to an unhandled exception (500 error code).
            // See the `Update` handler in the account controller for more info.
            _ = updateTask.Result;

            var deleteAccountRes = deleteTask.Result;

            // deleteAccountRes.EnsureSuccessStatusCode();
            Assert.IsTrue(deleteAccountRes);
        }