Exemple #1
0
        public void IsReadyForExternalAcquireLockRequests()
        {
            using (MockBackgroundFileSystemTaskRunner backgroundTaskRunner = new MockBackgroundFileSystemTaskRunner())
                using (MockFileSystemVirtualizer fileSystemVirtualizer = new MockFileSystemVirtualizer(this.Repo.Context, this.Repo.GitObjects))
                    using (MockGitIndexProjection gitIndexProjection = new MockGitIndexProjection(new[] { "test.txt" }))
                        using (FileSystemCallbacks fileSystemCallbacks = new FileSystemCallbacks(
                                   this.Repo.Context,
                                   this.Repo.GitObjects,
                                   RepoMetadata.Instance,
                                   new MockBlobSizes(),
                                   gitIndexProjection: gitIndexProjection,
                                   backgroundFileSystemTaskRunner: backgroundTaskRunner,
                                   fileSystemVirtualizer: fileSystemVirtualizer))
                        {
                            string denyMessage;
                            fileSystemCallbacks.IsReadyForExternalAcquireLockRequests(
                                new NamedPipeMessages.LockData(
                                    pid: 0,
                                    isElevated: false,
                                    checkAvailabilityOnly: false,
                                    parsedCommand: "git dummy-command"),
                                out denyMessage).ShouldBeFalse();
                            denyMessage.ShouldEqual("Waiting for mount to complete");

                            string error;
                            fileSystemCallbacks.TryStart(out error).ShouldBeTrue();
                            gitIndexProjection.ProjectionParseComplete = false;
                            fileSystemCallbacks.IsReadyForExternalAcquireLockRequests(
                                new NamedPipeMessages.LockData(
                                    pid: 0,
                                    isElevated: false,
                                    checkAvailabilityOnly: false,
                                    parsedCommand: "git dummy-command"),
                                out denyMessage).ShouldBeFalse();
                            denyMessage.ShouldEqual("Waiting for GVFS to parse index and update placeholder files");

                            // Put something on the background queue
                            fileSystemCallbacks.OnFileCreated("NewFilePath.txt");
                            backgroundTaskRunner.Count.ShouldEqual(1);
                            fileSystemCallbacks.IsReadyForExternalAcquireLockRequests(
                                new NamedPipeMessages.LockData(
                                    pid: 0,
                                    isElevated: false,
                                    checkAvailabilityOnly: false,
                                    parsedCommand: "git dummy-command"),
                                out denyMessage).ShouldBeFalse();
                            denyMessage.ShouldEqual("Waiting for background operations to complete and for GVFS to release the lock");

                            backgroundTaskRunner.BackgroundTasks.Clear();
                            gitIndexProjection.ProjectionParseComplete = true;
                            fileSystemCallbacks.IsReadyForExternalAcquireLockRequests(
                                new NamedPipeMessages.LockData(
                                    pid: 0,
                                    isElevated: false,
                                    checkAvailabilityOnly: false,
                                    parsedCommand: "git dummy-command"),
                                out denyMessage).ShouldBeTrue();
                            denyMessage.ShouldEqual("Waiting for GVFS to release the lock");

                            fileSystemCallbacks.Stop();
                        }
        }
Exemple #2
0
        public void IsReadyForExternalAcquireLockRequests()
        {
            Mock <IPlaceholderCollection> mockPlaceholderDb = new Mock <IPlaceholderCollection>(MockBehavior.Strict);

            mockPlaceholderDb.Setup(x => x.GetCount()).Returns(1);
            Mock <ISparseCollection> mockSparseDb = new Mock <ISparseCollection>(MockBehavior.Strict);

            using (MockBackgroundFileSystemTaskRunner backgroundTaskRunner = new MockBackgroundFileSystemTaskRunner())
                using (MockFileSystemVirtualizer fileSystemVirtualizer = new MockFileSystemVirtualizer(this.Repo.Context, this.Repo.GitObjects))
                    using (MockGitIndexProjection gitIndexProjection = new MockGitIndexProjection(new[] { "test.txt" }))
                        using (FileSystemCallbacks fileSystemCallbacks = new FileSystemCallbacks(
                                   this.Repo.Context,
                                   this.Repo.GitObjects,
                                   RepoMetadata.Instance,
                                   new MockBlobSizes(),
                                   gitIndexProjection: gitIndexProjection,
                                   backgroundFileSystemTaskRunner: backgroundTaskRunner,
                                   fileSystemVirtualizer: fileSystemVirtualizer,
                                   placeholderDatabase: mockPlaceholderDb.Object,
                                   sparseCollection: mockSparseDb.Object))
                        {
                            string denyMessage;
                            fileSystemCallbacks.IsReadyForExternalAcquireLockRequests(
                                new NamedPipeMessages.LockData(
                                    pid: 0,
                                    isElevated: false,
                                    checkAvailabilityOnly: false,
                                    parsedCommand: "git dummy-command",
                                    gitCommandSessionId: "123"),
                                out denyMessage).ShouldBeFalse();
                            denyMessage.ShouldEqual("Waiting for GVFS to parse index and update placeholder files");

                            string error;
                            fileSystemCallbacks.TryStart(out error).ShouldBeTrue();
                            gitIndexProjection.ProjectionParseComplete = false;
                            fileSystemCallbacks.IsReadyForExternalAcquireLockRequests(
                                new NamedPipeMessages.LockData(
                                    pid: 0,
                                    isElevated: false,
                                    checkAvailabilityOnly: false,
                                    parsedCommand: "git dummy-command",
                                    gitCommandSessionId: "123"),
                                out denyMessage).ShouldBeFalse();
                            denyMessage.ShouldEqual("Waiting for GVFS to parse index and update placeholder files");

                            // Put something on the background queue
                            fileSystemCallbacks.OnFileCreated("NewFilePath.txt");
                            backgroundTaskRunner.Count.ShouldEqual(1);
                            fileSystemCallbacks.IsReadyForExternalAcquireLockRequests(
                                new NamedPipeMessages.LockData(
                                    pid: 0,
                                    isElevated: false,
                                    checkAvailabilityOnly: false,
                                    parsedCommand: "git dummy-command",
                                    gitCommandSessionId: "123"),
                                out denyMessage).ShouldBeFalse();
                            denyMessage.ShouldEqual("Waiting for GVFS to release the lock");

                            backgroundTaskRunner.BackgroundTasks.Clear();
                            gitIndexProjection.ProjectionParseComplete = true;
                            fileSystemCallbacks.IsReadyForExternalAcquireLockRequests(
                                new NamedPipeMessages.LockData(
                                    pid: 0,
                                    isElevated: false,
                                    checkAvailabilityOnly: false,
                                    parsedCommand: "git dummy-command",
                                    gitCommandSessionId: "123"),
                                out denyMessage).ShouldBeTrue();
                            denyMessage.ShouldEqual("Waiting for GVFS to release the lock");

                            fileSystemCallbacks.Stop();
                        }

            mockPlaceholderDb.VerifyAll();
            mockSparseDb.VerifyAll();
        }