public static async Task UserControllerConcurrencyFuzzing(ICoyoteRuntime runtime) { const int transacriptLength = 4; var controller = new UserController(); 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 userTasks = new List <Task <ActionResult <User> > >(); var addressTasks = new List <Task <ActionResult <Address> > >(); for (int i = 0; i < transacriptLength; i++) { var choice = runtime.RandomInteger(transacriptLength); switch (choice) { case 0: userTasks.Add(controller.CreateUser(userName, emailAddress, phoneNumber, mailingAddress, billingAddress)); break; case 1: addressTasks.Add(controller.UpdateUserAddress(userName, mailingAddress, billingAddress)); break; case 2: userTasks.Add(controller.DeleteUser(userName)); break; case 3: userTasks.Add(controller.GetUser(userName)); break; } } var tasks = new List <Task>(); tasks.AddRange(userTasks); tasks.AddRange(addressTasks); await Task.WhenAll(tasks); userTasks.ForEach(t => CheckUserTaskResult(t)); addressTasks.ForEach(t => CheckAddressTaskResult(t)); }
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)); }
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])); }