Example #1
0
        public static async Task ConcurrentPictureCreates(ICoyoteRuntime runtime)
        {
            var userName        = "******";
            var emailAddress    = "*****@*****.**";
            var phoneNumber     = "425-123-1234";
            var mailingAddress  = "101 100th Ave NE Redmond WA";
            var billingAddress  = "101 100th Ave NE Redmond WA";
            var albumName       = "myAlbum";
            var pictureName     = "pic.jpg";
            var pictureContents = "0x2321";

            var userController = new UserController();
            var createResult   = await userController.CreateUser(userName, emailAddress, phoneNumber, mailingAddress, billingAddress);

            Assert(createResult.Success);

            var galleryController = new GalleryController();
            var createAlbumResult = await galleryController.CreateAlbum(userName, albumName);

            Assert(createAlbumResult.Success);
            CheckAlbum(createAlbumResult.Response);

            var pictureCreateTask1 = galleryController.UploadPicture(userName, albumName, pictureName, pictureContents);
            var pictureCreateTask2 = galleryController.UploadPicture(userName, albumName, pictureName, pictureContents);
            await Task.WhenAll(pictureCreateTask1, pictureCreateTask2);

            Assert(pictureCreateTask1.Result.Success ^ pictureCreateTask2.Result.Success);

            var picture = pictureCreateTask1.Result.Success ?
                          pictureCreateTask1.Result.Response :
                          pictureCreateTask2.Result.Response;

            CheckPicture(picture);
        }
Example #2
0
        public static async Task ConcurrentAlbumCreates(ICoyoteRuntime runtime)
        {
            var userName       = "******";
            var emailAddress   = "*****@*****.**";
            var phoneNumber    = "425-123-1234";
            var mailingAddress = "101 100th Ave NE Redmond WA";
            var billingAddress = "101 100th Ave NE Redmond WA";
            var albumName      = "myAlbum";

            var storageProvider = new AzureStorageProvider("Test", new Logger("Test"));

            var userController = new UserController();
            var createResult   = await userController.CreateUser(userName, emailAddress, phoneNumber, mailingAddress, billingAddress);

            Assert(createResult.Success);
            CheckUser(createResult.Response);
            Assert(!await storageProvider.DoesAccountExits(userName));

            var galleryController = new GalleryController();
            var createAlbumTask1  = galleryController.CreateAlbum(userName, albumName);
            var createAlbumTask2  = galleryController.CreateAlbum(userName, albumName);

            await Task.WhenAll(createAlbumTask1, createAlbumTask2);

            Assert(createAlbumTask1.Result.Success ^ createAlbumTask2.Result.Success);
            Assert(await storageProvider.DoesAccountExits(userName));
            Assert(await storageProvider.DoesContainerExist(userName, albumName));

            var album = createAlbumTask1.Result.Success ?
                        createAlbumTask1.Result.Response :
                        createAlbumTask2.Result.Response;

            CheckAlbum(album);
        }
Example #3
0
        public static async Task ConcurrentAlbumDeletes(ICoyoteRuntime runtime)
        {
            var userName       = "******";
            var emailAddress   = "*****@*****.**";
            var phoneNumber    = "425-123-1234";
            var mailingAddress = "101 100th Ave NE Redmond WA";
            var billingAddress = "101 100th Ave NE Redmond WA";
            var albumName      = "myAlbum";

            var storageProvider = new AzureStorageProvider("Test", new Logger("Test"));

            var userController = new UserController();
            var createResult   = await userController.CreateUser(userName, emailAddress, phoneNumber, mailingAddress, billingAddress);

            Assert(createResult.Success);
            CheckUser(createResult.Response);
            Assert(!await storageProvider.DoesAccountExits(userName));

            var galleryController = new GalleryController();
            var createAlbumResult = await galleryController.CreateAlbum(userName, albumName);

            Assert(createAlbumResult.Success);
            CheckAlbum(createAlbumResult.Response);
            Assert(await storageProvider.DoesAccountExits(userName));

            var albumDeleteTask1 = galleryController.DeleteAlbum(userName, albumName);
            var albumDeleteTask2 = galleryController.DeleteAlbum(userName, albumName);
            await Task.WhenAll(albumDeleteTask1, albumDeleteTask2);

            Assert(albumDeleteTask1.Result.Success ^ albumDeleteTask2.Result.Success);
            var album = albumDeleteTask1.Result.Success ?
                        albumDeleteTask1.Result.Response :
                        albumDeleteTask2.Result.Response;

            CheckAlbum(album);

            // Assert that even though the album has been deleted the storage account is still there
            // as it should only be deleted when the user is deleted
            Assert(await storageProvider.DoesAccountExits(userName));
        }
Example #4
0
        public static async Task GalleryServiceConcurrencyFuzzing(ICoyoteRuntime runtime)
        {
            const int transacriptLength = 9;

            var userController    = new UserController();
            var galleryController = new GalleryController();

            var userName       = "******";
            var emailAddress   = "*****@*****.**";
            var phoneNumber    = "425-123-1234";
            var mailingAddress = "101 100th Ave NE Redmond, WA";
            var billingAddress = "101 100th Ave NE Redmond, WA";
            var albumName      = "Holiday";
            var pictureName    = "Beach.jpg";
            var pictureContent = "923bac12";

            var userTasks    = new List <Task <ActionResult <User> > >();
            var addressTasks = new List <Task <ActionResult <Address> > >();
            var albumTasks   = new List <Task <ActionResult <Album> > >();
            var pictureTasks = new List <Task <ActionResult <Picture> > >();

            for (int i = 0; i < transacriptLength; i++)
            {
                var choice = runtime.RandomInteger(transacriptLength);

                switch (choice)
                {
                case 0:
                    userTasks.Add(userController.CreateUser(userName, emailAddress, phoneNumber, mailingAddress, billingAddress));
                    break;

                case 1:
                    addressTasks.Add(userController.UpdateUserAddress(userName, mailingAddress, billingAddress));
                    break;

                case 2:
                    userTasks.Add(userController.DeleteUser(userName));
                    break;

                case 3:
                    userTasks.Add(userController.GetUser(userName));
                    break;

                case 4:
                    albumTasks.Add(galleryController.CreateAlbum(userName, albumName));
                    break;

                case 5:
                    albumTasks.Add(galleryController.DeleteAlbum(userName, albumName));
                    break;

                case 6:
                    pictureTasks.Add(galleryController.UploadPicture(userName, albumName, pictureName, pictureContent));
                    break;

                case 7:
                    pictureTasks.Add(galleryController.DeletePicture(userName, albumName, pictureName));
                    break;

                case 8:
                    pictureTasks.Add(galleryController.RetrievePicture(userName, albumName, pictureName));
                    break;
                }
            }

            var tasks = new List <Task>();

            tasks.AddRange(userTasks);
            tasks.AddRange(addressTasks);
            tasks.AddRange(albumTasks);
            tasks.AddRange(pictureTasks);
            await Task.WhenAll(tasks.ToArray());

            userTasks.ForEach(t => CheckUserTaskResult(t));
            addressTasks.ForEach(t => CheckAddressTaskResult(t));
            albumTasks.ForEach(t => CheckAlbumTaskResult(t));
            pictureTasks.ForEach(t => CheckPictureTaskResult(t));
        }
Example #5
0
        public static async Task DeleteWithConcurrentAPIs(ICoyoteRuntime runtime)
        {
            var userName        = "******";
            var emailAddress    = "*****@*****.**";
            var phoneNumber     = "425-123-1234";
            var mailingAddress  = "101 100th Ave NE Redmond WA";
            var billingAddress  = "101 100th Ave NE Redmond WA";
            var albumName       = "myAlbum";
            var pictureName     = "pic.jpg";
            var pictureContents = "0x2321";

            var userController    = new UserController();
            var galleryController = new GalleryController();

            var logger  = new Logger("DeleteWithConcurrentAPIs");
            var db      = new DatabaseProvider("Test", logger);
            var storage = new AzureStorageProvider("Test", logger);

            var createResult = await userController.CreateUser(userName, emailAddress, phoneNumber, mailingAddress, billingAddress);

            Assert(createResult.Success);
            Assert(createResult.Response.UserName == userName && createResult.Response.EmailAddress == emailAddress);
            var doc = await db.GetDocument(Constants.UserCollection, userName);

            Assert(doc[Constants.EmailAddress] == emailAddress);

            var tasks = new List <Task>();

            // We start the delete operation, along with a number of concurrenct APIs in the background
            // which should not interfere with the invariant we check at the end of the delete operation
            var deleteResultTask = userController.DeleteUser(userName);

            tasks.Add(deleteResultTask);

            const int transcriptLength = 7;

            for (int i = 0; i < transcriptLength; i++)
            {
                var choice = runtime.RandomInteger(transcriptLength);

                switch (choice)
                {
                case 0:
                    tasks.Add(userController.UpdateUserAddress(userName, mailingAddress, billingAddress));
                    break;

                case 1:
                    tasks.Add(userController.GetUser(userName));
                    break;

                case 2:
                    tasks.Add(galleryController.CreateAlbum(userName, albumName));
                    break;

                case 3:
                    tasks.Add(galleryController.DeleteAlbum(userName, albumName));
                    break;

                case 4:
                    tasks.Add(galleryController.UploadPicture(userName, albumName, pictureName, pictureContents));
                    break;

                case 5:
                    tasks.Add(galleryController.RetrievePicture(userName, albumName, pictureName));
                    break;

                case 6:
                    tasks.Add(galleryController.DeletePicture(userName, albumName, pictureName));
                    break;
                }
            }

            Task.WaitAll(tasks.ToArray());

            var deleteResult = deleteResultTask.Result;

            Assert(deleteResult.Success);
            Assert(!await db.DoesDocumentExist(Constants.UserCollection, userName));
            Assert(!await storage.DoesAccountExits(doc[Constants.UniqueId]));
        }