private void CreateShareInternal(Func <string> shareNameProvider, Action <IExecutionResult, string> assertAction, bool validateNotExists = true) { string shareName = shareNameProvider(); if (validateNotExists) { while (fileUtil.Client.GetShareReference(shareName).Exists()) { shareName = shareNameProvider(); } } try { CommandAgent.NewFileShare(shareName); assertAction(CommandAgent.Invoke(), shareName); } finally { if (validateNotExists) { fileUtil.DeleteFileShareIfExists(shareName); } } }
public void CreateShareWhichHasBeenDeletedAndGCed() { const int CreateShareInterval = 10000; const int CreateShareRetryLimit = 10; string fileShareName = CloudFileUtil.GenerateUniqueFileShareName(); var fileShare = fileUtil.EnsureFileShareExists(fileShareName); // Delete the share first. fileShare.Delete(); Stopwatch watch = Stopwatch.StartNew(); // Try to create the share try { for (int i = 0; i < CreateShareRetryLimit; i++) { Thread.Sleep(CreateShareInterval); Test.Info("Try to create a share which has just been deleted. RetryCount = {0}", i); CommandAgent.NewFileShare(fileShareName); var result = CommandAgent.Invoke(); if (!CommandAgent.HadErrors) { Test.Info("Successfully created the file share at round {0}.", i); return; } CommandAgent.AssertErrors(errorRecord => errorRecord.AssertError(AssertUtil.ShareBeingDeletedFullQualifiedErrorId)); CommandAgent.Clear(); } Test.Error("Failed to create the file share within the given retry count {0}. Total time passed is {1}", CreateShareRetryLimit, watch.Elapsed); } finally { fileUtil.DeleteFileShareIfExists(fileShareName); } }