Esempio n. 1
0
        /// <summary>
        /// Verifies no instances are leaked.
        /// </summary>
        public static void CheckProcessForInstanceLeaks()
        {
#if !MANAGEDESENT_ON_WSA // Not exposed in MSDK
            int numInstances;
            JET_INSTANCE_INFO[] instances;
            Api.JetGetInstanceInfo(out numInstances, out instances);

            if (numInstances != 0)
            {
                IsamTestHelper.ConsoleWriteLine("There are {0} instances remaining! They are:", numInstances);
                foreach (var instanceInfo in instances)
                {
                    string databaseName = string.Empty;
                    if (instanceInfo.szDatabaseFileName != null && instanceInfo.szDatabaseFileName.Count > 0)
                    {
                        databaseName = instanceInfo.szDatabaseFileName[0];
                    }

                    IsamTestHelper.ConsoleWriteLine(
                        "   szInstanceName={0}, szDatabaseName={1}",
                        instanceInfo.szInstanceName,
                        databaseName);
                }
            }

            Assert.AreEqual(0, numInstances);
#endif // !MANAGEDESENT_ON_WSA
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a new random directory in the current working directory. This
        /// should be used to ensure that each test runs in its own directory.
        /// </summary>
        /// <returns>The name of the directory.</returns>
        public static string CreateRandomDirectory()
        {
            string myDir = IsamTestHelper.PathGetRandomFileName() + @"\";

            IsamTestHelper.DirectoryCreateDirectory(myDir);
            return(myDir);
        }
Esempio n. 3
0
        /// <summary>
        /// Perform an action and retry on I/O failure, with a 1 second
        /// sleep between retries.
        /// </summary>
        /// <param name="action">The action to perform.</param>
        private static void PerformActionWithRetry(Action action)
        {
            for (int attempt = 1; attempt <= MaxAttempts; ++attempt)
            {
                try
                {
                    action();
                    return;
                }
                catch (UnauthorizedAccessException)
                {
                    if (MaxAttempts == attempt)
                    {
                        throw;
                    }
                }
                catch (IOException)
                {
                    if (MaxAttempts == attempt)
                    {
                        throw;
                    }
                }

                IsamTestHelper.ThreadSleep(TimeSpan.FromSeconds(1));
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Delete a directory, retrying the operation if the delete fails.
 /// </summary>
 /// <param name="directory">
 /// The directory to delete.
 /// </param>
 public static void DeleteDirectoryWithRetry(string directory)
 {
     PerformActionWithRetry(
         () =>
     {
         if (IsamTestHelper.DirectoryExists(directory))
         {
             IsamTestHelper.DirectoryDelete(directory, true);
         }
     });
 }
Esempio n. 5
0
 /// <summary>
 /// Delete a file, retrying the operation if the delete fails.
 /// </summary>
 /// <param name="file">
 /// The file to delete.
 /// </param>
 public static void DeleteFileWithRetry(string file)
 {
     PerformActionWithRetry(() => IsamTestHelper.FileDelete(file));
 }