Exemple #1
0
        public static GSDFunctionalTestEnlistment CloneAndMountEnlistmentWithSpacesInPath(string pathToGvfs, string commitish = null)
        {
            string enlistmentRoot = GSDFunctionalTestEnlistment.GetUniqueEnlistmentRootWithSpaces();
            string localCache     = GSDFunctionalTestEnlistment.GetRepoSpecificLocalCacheRoot(enlistmentRoot);

            return(CloneAndMount(pathToGvfs, enlistmentRoot, commitish, localCache));
        }
Exemple #2
0
        public static GSDFunctionalTestEnlistment CloneAndMountWithPerRepoCache(string pathToGvfs, bool skipPrefetch)
        {
            string enlistmentRoot = GSDFunctionalTestEnlistment.GetUniqueEnlistmentRoot();
            string localCache     = GSDFunctionalTestEnlistment.GetRepoSpecificLocalCacheRoot(enlistmentRoot);

            return(CloneAndMount(pathToGvfs, enlistmentRoot, null, localCache, skipPrefetch));
        }
        private static string GetModifiedPathsContents(GSDFunctionalTestEnlistment enlistment, FileSystemRunner fileSystem)
        {
            enlistment.WaitForBackgroundOperations();
            string modifiedPathsDatabase = Path.Combine(enlistment.DotGSDRoot, TestConstants.Databases.ModifiedPaths);

            modifiedPathsDatabase.ShouldBeAFile(fileSystem);
            return(GSDHelpers.ReadAllTextFromWriteLockedFile(modifiedPathsDatabase));
        }
        public static void ModifiedPathsShouldContain(GSDFunctionalTestEnlistment enlistment, FileSystemRunner fileSystem, params string[] gitPaths)
        {
            string modifedPathsContents = GetModifiedPathsContents(enlistment, fileSystem);

            string[] modifedPathLines = modifedPathsContents.Split(new[] { ModifiedPathsNewLine }, StringSplitOptions.None);
            foreach (string gitPath in gitPaths)
            {
                modifedPathLines.ShouldContain(path => path.Equals(ModifedPathsLineAddPrefix + gitPath, StringComparison.OrdinalIgnoreCase));
            }
        }
Exemple #5
0
        public static GSDFunctionalTestEnlistment CloneAndMount(
            string pathToGvfs,
            string commitish      = null,
            string localCacheRoot = null,
            bool skipPrefetch     = false)
        {
            string enlistmentRoot = GSDFunctionalTestEnlistment.GetUniqueEnlistmentRoot();

            return(CloneAndMount(pathToGvfs, enlistmentRoot, commitish, localCacheRoot, skipPrefetch));
        }
 /// <summary>
 /// Run the specified Git command. This method will return once the GSDLock has been acquired.
 /// </summary>
 /// <param name="processId">The ID of the process that acquired the lock.</param>
 /// <returns><see cref="ManualResetEvent"/> that can be signaled to exit the lock acquisition program.</returns>
 public static ManualResetEventSlim RunGitCommandWithWaitAndStdIn(
     GSDFunctionalTestEnlistment enlistment,
     int resetTimeout,
     string command,
     string stdinToQuit,
     out int processId)
 {
     return
         (RunCommandWithWaitAndStdIn(
              enlistment,
              resetTimeout,
              Properties.Settings.Default.PathToGit,
              command,
              "git " + command,
              stdinToQuit,
              out processId));
 }
Exemple #7
0
        private static GSDFunctionalTestEnlistment CloneAndMount(string pathToGvfs, string enlistmentRoot, string commitish, string localCacheRoot, bool skipPrefetch = false)
        {
            GSDFunctionalTestEnlistment enlistment = new GSDFunctionalTestEnlistment(
                pathToGvfs,
                enlistmentRoot ?? GetUniqueEnlistmentRoot(),
                GSDTestConfig.RepoToClone,
                commitish ?? Properties.Settings.Default.Commitish,
                localCacheRoot ?? GSDTestConfig.LocalCacheRoot);

            try
            {
                enlistment.CloneAndMount(skipPrefetch);
            }
            catch (Exception e)
            {
                Console.WriteLine("Unhandled exception in CloneAndMount: " + e.ToString());
                TestResultsHelper.OutputGSDLogs(enlistment);
                throw;
            }

            return(enlistment);
        }
        /// <summary>
        /// Acquire the GSDLock. This method will return once the GSDLock has been acquired.
        /// </summary>
        /// <param name="processId">The ID of the process that acquired the lock.</param>
        /// <returns><see cref="ManualResetEvent"/> that can be signaled to exit the lock acquisition program.</returns>
        public static ManualResetEventSlim AcquireGSDLock(
            GSDFunctionalTestEnlistment enlistment,
            out int processId,
            int resetTimeout     = Timeout.Infinite,
            bool skipReleaseLock = false)
        {
            string args = LockHolderCommandPath;

            if (skipReleaseLock)
            {
                args += " --skip-release-lock";
            }

            return(RunCommandWithWaitAndStdIn(
                       enlistment,
                       resetTimeout,
                       "dotnet",
                       args,
                       GitHelpers.LockHolderCommandName,
                       "done",
                       out processId));
        }
        public static void ValidateGitCommand(
            GSDFunctionalTestEnlistment enlistment,
            ControlGitRepo controlGitRepo,
            string command,
            params object[] args)
        {
            command = string.Format(command, args);
            string controlRepoRoot = controlGitRepo.RootPath;
            string gvfsRepoRoot    = enlistment.RepoRoot;

            ProcessResult expectedResult = GitProcess.InvokeProcess(controlRepoRoot, command);
            ProcessResult actualResult   = GitHelpers.InvokeGitAgainstGSDRepo(gvfsRepoRoot, command);

            ErrorsShouldMatch(command, expectedResult, actualResult);
            actualResult.Output.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)
            .ShouldMatchInOrder(expectedResult.Output.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries), LinesAreEqual, command + " Output Lines");

            if (command != "status")
            {
                ValidateGitCommand(enlistment, controlGitRepo, "status");
            }
        }
Exemple #10
0
        public static void ModifiedPathsContentsShouldEqual(GSDFunctionalTestEnlistment enlistment, FileSystemRunner fileSystem, string contents)
        {
            string modifedPathsContents = GetModifiedPathsContents(enlistment, fileSystem);

            modifedPathsContents.ShouldEqual(contents);
        }
Exemple #11
0
        /// <summary>
        /// Run the specified command as an external program. This method will return once the GSDLock has been acquired.
        /// </summary>
        /// <param name="processId">The ID of the process that acquired the lock.</param>
        /// <returns><see cref="ManualResetEvent"/> that can be signaled to exit the lock acquisition program.</returns>
        private static ManualResetEventSlim RunCommandWithWaitAndStdIn(
            GSDFunctionalTestEnlistment enlistment,
            int resetTimeout,
            string pathToCommand,
            string args,
            string lockingProcessCommandName,
            string stdinToQuit,
            out int processId)
        {
            ManualResetEventSlim resetEvent = new ManualResetEventSlim(initialState: false);

            ProcessStartInfo processInfo = new ProcessStartInfo(pathToCommand);

            processInfo.WorkingDirectory       = enlistment.RepoRoot;
            processInfo.UseShellExecute        = false;
            processInfo.RedirectStandardOutput = true;
            processInfo.RedirectStandardError  = true;
            processInfo.RedirectStandardInput  = true;
            processInfo.Arguments = args;

            Process      holdingProcess = Process.Start(processInfo);
            StreamWriter stdin          = holdingProcess.StandardInput;

            processId = holdingProcess.Id;

            enlistment.WaitForLock(lockingProcessCommandName);

            Task.Run(
                () =>
            {
                resetEvent.Wait(resetTimeout);

                try
                {
                    // Make sure to let the holding process end.
                    if (stdin != null)
                    {
                        stdin.WriteLine(stdinToQuit);
                        stdin.Close();
                    }

                    if (holdingProcess != null)
                    {
                        bool holdingProcessHasExited = holdingProcess.WaitForExit(10000);

                        if (!holdingProcess.HasExited)
                        {
                            holdingProcess.Kill();
                        }

                        holdingProcess.Dispose();

                        holdingProcessHasExited.ShouldBeTrue("Locking process did not exit in time.");
                    }
                }
                catch (Exception ex)
                {
                    Assert.Fail($"{nameof(RunCommandWithWaitAndStdIn)} exception closing stdin {ex.ToString()}");
                }
                finally
                {
                    resetEvent.Set();
                }
            });

            return(resetEvent);
        }