private static GVFSFunctionalTestEnlistment CloneAndMount(string pathToGvfs, string enlistmentRoot, string commitish, string localCacheRoot, bool skipPrefetch = false)
        {
            GVFSFunctionalTestEnlistment enlistment = new GVFSFunctionalTestEnlistment(
                pathToGvfs,
                enlistmentRoot ?? GetUniqueEnlistmentRoot(),
                GVFSTestConfig.RepoToClone,
                commitish ?? Properties.Settings.Default.Commitish,
                localCacheRoot ?? GVFSTestConfig.LocalCacheRoot);

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

            return(enlistment);
        }
Beispiel #2
0
        public static void ValidateGitCommand(
            GVFSFunctionalTestEnlistment 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.InvokeGitAgainstGVFSRepo(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");
            }
        }
        public static GVFSFunctionalTestEnlistment CloneAndMount(string pathToGvfs, string commitish = null)
        {
            GVFSFunctionalTestEnlistment enlistment = new GVFSFunctionalTestEnlistment(
                pathToGvfs,
                Properties.Settings.Default.EnlistmentRoot,
                Properties.Settings.Default.RepoToClone,
                commitish == null ? Properties.Settings.Default.Commitish : commitish);

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

            return(enlistment);
        }
Beispiel #4
0
        public static void ModifiedPathsContentsShouldEqual(GVFSFunctionalTestEnlistment enlistment, FileSystemRunner fileSystem, string contents)
        {
            string modifedPathsContents = GetModifiedPathsContents(enlistment, fileSystem);

            modifedPathsContents.ShouldEqual(contents);
        }
Beispiel #5
0
        /// <summary>
        /// Run the specified command as an external program. This method will return once the GVFSLock 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(
            GVFSFunctionalTestEnlistment 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);
        }
Beispiel #6
0
 public static ManualResetEventSlim AcquireGVFSLock(
     GVFSFunctionalTestEnlistment enlistment,
     int resetTimeout = Timeout.Infinite)
 {
     return(RunGitCommandWithWaitAndStdIn(enlistment, resetTimeout: resetTimeout, command: "hash-object --stdin", stdinToQuit: "dummy"));
 }
Beispiel #7
0
        public static GVFSFunctionalTestEnlistment CloneAndMount(string pathToGvfs, string commitish = null, string localCacheRoot = null)
        {
            string enlistmentRoot = GVFSFunctionalTestEnlistment.GetUniqueEnlistmentRoot();

            return(CloneAndMount(pathToGvfs, enlistmentRoot, commitish, localCacheRoot));
        }
Beispiel #8
0
 public GVFSProcess(GVFSFunctionalTestEnlistment enlistment)
     : this(GVFSTestConfig.PathToGVFS, enlistment.EnlistmentRoot, Path.Combine(enlistment.EnlistmentRoot, GVFSTestConfig.DotGVFSRoot))
 {
 }