示例#1
0
        public void SuccessForBatchObjectDownloadJob()
        {
            using (JsonEtwTracer tracer = CreateTracer())
            {
                MockEnlistment     enlistment     = new MockEnlistment();
                MockHttpGitObjects httpGitObjects = new MockHttpGitObjects(tracer, enlistment);
                httpGitObjects.AddBlobContent(FakeSha, FakeShaContents);
                MockPhysicalGitObjects gitObjects = new MockPhysicalGitObjects(tracer, enlistment, httpGitObjects);

                BlockingCollection <string> input = new BlockingCollection <string>();
                input.Add(FakeSha);
                input.CompleteAdding();

                BatchObjectDownloadJob dut = new BatchObjectDownloadJob(1, 1, input, new BlockingCollection <string>(), tracer, enlistment, httpGitObjects, gitObjects);
                dut.Start();
                dut.WaitForCompletion();

                string sha;
                input.TryTake(out sha).ShouldEqual(false);
                dut.AvailablePacks.Count.ShouldEqual(0);

                dut.AvailableObjects.Count.ShouldEqual(1);
                string output = dut.AvailableObjects.Take();
                output.ShouldEqual(FakeSha);
            }
        }
示例#2
0
        public void CanGetCacheServerWithNoConfig()
        {
            MockEnlistment enlistment = this.CreateEnlistment();

            this.ValidateIsNone(enlistment, CacheServerResolver.GetCacheServerFromConfig(enlistment));
            CacheServerResolver.GetUrlFromConfig(enlistment).ShouldEqual(enlistment.RepoUrl);
        }
示例#3
0
        public void TwoThreadsInterleavingFailuresShouldntStompASuccess()
        {
            MockTracer     tracer     = new MockTracer();
            MockEnlistment enlistment = new MockEnlistment();
            MockGitProcess gitProcess = new MockGitProcess(enlistment);

            GitAuthentication dut = new GitAuthentication(gitProcess);

            string thread1Auth;
            string thread2Auth;
            string error;

            // Populate an initial PAT on two threads
            dut.TryGetCredentials(tracer, out thread1Auth, out error).ShouldEqual(true);
            dut.TryGetCredentials(tracer, out thread2Auth, out error).ShouldEqual(true);

            // Simulate a 401 error on one threads
            dut.RevokeAndCheckCanRetry(thread1Auth).ShouldEqual(true);

            // That thread then retries and succeeds
            dut.TryGetCredentials(tracer, out thread1Auth, out error).ShouldEqual(true);
            dut.ConfirmCredentialsWorked(thread1Auth);

            // If the second thread fails with the old PAT, it shouldn't stomp the new PAT
            dut.RevokeAndCheckCanRetry(thread2Auth).ShouldEqual(true);

            // The second thread should be able to get a PAT
            dut.TryGetCredentials(tracer, out thread2Auth, out error).ShouldEqual(true);
            thread2Auth.ShouldEqual(thread1Auth, "The second thread stomp the first threads good auth string");
        }
示例#4
0
        public void TwoThreadsInterleavingFailuresStillRetriesOnce()
        {
            MockTracer     tracer     = new MockTracer();
            MockEnlistment enlistment = new MockEnlistment();
            MockGitProcess gitProcess = new MockGitProcess(enlistment);

            GitAuthentication dut = new GitAuthentication(gitProcess);

            string thread1Auth;
            string thread2Auth;
            string error;

            // Populate an initial PAT on two threads
            dut.TryGetCredentials(tracer, out thread1Auth, out error).ShouldEqual(true);
            dut.TryGetCredentials(tracer, out thread2Auth, out error).ShouldEqual(true);

            // Simulate a 401 error on one threads
            dut.RevokeAndCheckCanRetry(thread1Auth).ShouldEqual(true);

            // That thread then retries
            dut.TryGetCredentials(tracer, out thread1Auth, out error).ShouldEqual(true);

            // The second thread fails with the old PAT
            dut.RevokeAndCheckCanRetry(thread2Auth).ShouldEqual(true);

            // The second thread should be able to get a PAT
            dut.TryGetCredentials(tracer, out thread2Auth, out error).ShouldEqual(true);
        }
示例#5
0
        public void CanGetCacheServerFromOldConfig()
        {
            MockEnlistment  enlistment  = this.CreateEnlistment(null, CacheServerUrl);
            CacheServerInfo cacheServer = CacheServerResolver.GetCacheServerFromConfig(enlistment);

            cacheServer.Url.ShouldEqual(CacheServerUrl);
            CacheServerResolver.GetUrlFromConfig(enlistment).ShouldEqual(CacheServerUrl);
        }
示例#6
0
        public void OnlyRequestsObjectsNotDownloaded()
        {
            string obj1Sha = new string('1', 40);
            string obj2Sha = new string('2', 40);

            BlockingCollection <string> input = new BlockingCollection <string>();

            input.Add(obj1Sha);
            input.Add(obj2Sha);
            input.CompleteAdding();

            int obj1Count = 0;
            int obj2Count = 0;

            Func <string, string> objectResolver = (oid) =>
            {
                if (oid.Equals(obj1Sha))
                {
                    obj1Count++;
                    return("Object1Contents");
                }

                if (oid.Equals(obj2Sha) && obj2Count++ == 1)
                {
                    return("Object2Contents");
                }

                return(null);
            };

            BlockingCollection <string> output  = new BlockingCollection <string>();
            MockTracer              tracer      = new MockTracer();
            MockEnlistment          enlistment  = new MockEnlistment();
            MockBatchHttpGitObjects httpObjects = new MockBatchHttpGitObjects(tracer, enlistment, objectResolver);

            BatchObjectDownloadJob dut = new BatchObjectDownloadJob(
                MaxParallel,
                ChunkSize,
                input,
                output,
                tracer,
                enlistment,
                httpObjects,
                new MockPhysicalGitObjects(tracer, enlistment, httpObjects));

            dut.Start();
            dut.WaitForCompletion();

            input.Count.ShouldEqual(0);
            output.Count.ShouldEqual(2);
            output.Take().ShouldEqual(obj1Sha);
            output.Take().ShouldEqual(obj2Sha);
            obj1Count.ShouldEqual(1);
            obj2Count.ShouldEqual(2);
        }
        public void CanResolveUrlAsRepoUrl()
        {
            MockEnlistment      enlistment = this.CreateEnlistment();
            CacheServerResolver resolver   = this.CreateResolver(enlistment);

            this.ValidateIsNone(enlistment, resolver.ResolveNameFromRemote(enlistment.RepoUrl, this.CreateGVFSConfig()));
            this.ValidateIsNone(enlistment, resolver.ResolveNameFromRemote(enlistment.RepoUrl + "/", this.CreateGVFSConfig()));
            this.ValidateIsNone(enlistment, resolver.ResolveNameFromRemote(enlistment.RepoUrl + "//", this.CreateGVFSConfig()));
            this.ValidateIsNone(enlistment, resolver.ResolveNameFromRemote(enlistment.RepoUrl.ToUpper(), this.CreateGVFSConfig()));
            this.ValidateIsNone(enlistment, resolver.ResolveNameFromRemote(enlistment.RepoUrl.ToUpper() + "/", this.CreateGVFSConfig()));
            this.ValidateIsNone(enlistment, resolver.ResolveNameFromRemote(enlistment.RepoUrl.ToLower(), this.CreateGVFSConfig()));
            this.ValidateIsNone(enlistment, resolver.ResolveNameFromRemote(enlistment.RepoUrl.ToLower() + "/", this.CreateGVFSConfig()));
        }
        public void CanParseAndResolveDefaultWhenServerAdvertisesNullListOfCacheServers()
        {
            MockEnlistment      enlistment = this.CreateEnlistment();
            CacheServerResolver resolver   = this.CreateResolver(enlistment);

            CacheServerInfo resolvedCacheServer;
            string          error;

            resolver.TryResolveUrlFromRemote(CacheServerInfo.ReservedNames.Default, this.CreateDefaultDeserializedGVFSConfig(), out resolvedCacheServer, out error)
            .ShouldEqual(true);

            this.ValidateIsNone(enlistment, resolvedCacheServer);
        }
        public void CanParseAndResolveOtherWhenServerAdvertisesNullListOfCacheServers()
        {
            MockEnlistment      enlistment = this.CreateEnlistment();
            CacheServerResolver resolver   = this.CreateResolver(enlistment);

            CacheServerInfo resolvedCacheServer;
            string          error;

            resolver.TryResolveUrlFromRemote(CacheServerInfo.ReservedNames.None, this.CreateDefaultDeserializedGVFSConfig(), out resolvedCacheServer, out error)
            .ShouldEqual(false, "Should not succeed in resolving the name 'None'");

            resolvedCacheServer.ShouldEqual(null);
            error.ShouldNotBeNull();
        }
示例#10
0
        public void ErrorsForIndexPackFile()
        {
            using (JsonEtwTracer tracer = CreateTracer())
            {
                MockEnlistment         enlistment = new MockEnlistment();
                MockPhysicalGitObjects gitObjects = new MockPhysicalGitObjects(tracer, enlistment, null);

                BlockingCollection <IndexPackRequest> input = new BlockingCollection <IndexPackRequest>();
                BlobDownloadRequest downloadRequest         = new BlobDownloadRequest(new string[] { FakeSha });
                input.Add(new IndexPackRequest("mock:\\path\\packFileName", downloadRequest));
                input.CompleteAdding();

                IndexPackJob dut = new IndexPackJob(1, input, new BlockingCollection <string>(), tracer, gitObjects);
                dut.Start();
                dut.WaitForCompletion();
            }
        }
示例#11
0
        public void CanParseAndResolveNoCacheServer()
        {
            MockEnlistment      enlistment = this.CreateEnlistment();
            CacheServerResolver resolver   = this.CreateResolver(enlistment);

            this.ValidateIsNone(enlistment, resolver.ParseUrlOrFriendlyName(NoneFriendlyName));
            this.ValidateIsNone(enlistment, resolver.ParseUrlOrFriendlyName(enlistment.RepoUrl));

            CacheServerInfo resolvedCacheServer;
            string          error;

            resolver.TryResolveUrlFromRemote(NoneFriendlyName, this.CreateGVFSConfig(), out resolvedCacheServer, out error)
            .ShouldEqual(false, "Should not succeed in resolving the name 'None'");

            resolvedCacheServer.ShouldEqual(null);
            error.ShouldNotBeNull();
        }
示例#12
0
        public void ShouldOnlyRetryAuthOnce()
        {
            MockTracer     tracer     = new MockTracer();
            MockEnlistment enlistment = new MockEnlistment();
            MockGitProcess gitProcess = new MockGitProcess(enlistment);

            GitAuthentication dut = new GitAuthentication(gitProcess);

            string authString;
            string error;

            dut.TryGetCredentials(tracer, out authString, out error).ShouldEqual(true, "Failed to get initial credential");

            dut.RevokeAndCheckCanRetry(authString).ShouldEqual(true, "Should retry once");

            dut.TryGetCredentials(tracer, out authString, out error).ShouldEqual(true, "Failed to retry getting credential on iteration");

            dut.RevokeAndCheckCanRetry(authString).ShouldEqual(false, "Should not retry more than once");
            dut.TryGetCredentials(tracer, out authString, out error).ShouldEqual(false, "TryGetCredential should not succeed during backoff");
        }
示例#13
0
        public void GitProcessFailuresAreRetried()
        {
            MockTracer     tracer     = new MockTracer();
            MockEnlistment enlistment = new MockEnlistment();
            MockGitProcess gitProcess = new MockGitProcess(enlistment);

            GitAuthentication dut = new GitAuthentication(gitProcess);

            string authString;
            string error;

            gitProcess.ShouldFail = true;

            dut.TryGetCredentials(tracer, out authString, out error).ShouldEqual(false, "Succeeded despite GitProcess returning failure");

            dut.RevokeAndCheckCanRetry(authString).ShouldEqual(true, "Should retry once");

            gitProcess.ShouldFail = false;

            dut.TryGetCredentials(tracer, out authString, out error).ShouldEqual(true, "Failed to get credential on retry");
        }
示例#14
0
        public void DoesNotRetryIfTryGetCredentialsFails()
        {
            MockTracer     tracer     = new MockTracer();
            MockEnlistment enlistment = new MockEnlistment();
            MockGitProcess gitProcess = new MockGitProcess(enlistment);

            GitAuthentication dut = new GitAuthentication(gitProcess);

            string authString;
            string error;

            dut.TryGetCredentials(tracer, out authString, out error).ShouldEqual(true, "Failed to get initial credential");

            dut.RevokeAndCheckCanRetry(authString).ShouldEqual(true, "Should retry once");

            gitProcess.ShouldFail = true;

            dut.TryGetCredentials(tracer, out authString, out error).ShouldEqual(false, "Succeeded despite GitProcess returning failure");

            dut.RevokeAndCheckCanRetry(authString).ShouldEqual(false, "Should not retry if GitProcess fails after retry");
            dut.TryGetCredentials(tracer, out authString, out error).ShouldEqual(false, "TryGetCredential should not succeed during backoff");
        }
示例#15
0
        public void CanRetryManyTimesIfTheresSomeSuccess()
        {
            MockTracer     tracer     = new MockTracer();
            MockEnlistment enlistment = new MockEnlistment();
            MockGitProcess gitProcess = new MockGitProcess(enlistment);

            GitAuthentication dut = new GitAuthentication(gitProcess);

            string authString;
            string error;

            for (int i = 0; i < 5; ++i)
            {
                dut.TryGetCredentials(tracer, out authString, out error).ShouldEqual(true, "Failed to get credential on iteration " + i + ": " + error);

                dut.RevokeAndCheckCanRetry(authString).ShouldEqual(true, "Did not retry after revoke on iteration: " + i);

                dut.TryGetCredentials(tracer, out authString, out error).ShouldEqual(true, "Failed to retry getting credential on iteration " + i + ": " + error);

                dut.ConfirmCredentialsWorked(authString);
            }
        }
示例#16
0
        public void ErrorsForBatchObjectDownloadJob()
        {
            using (JsonEtwTracer tracer = CreateTracer())
            {
                MockEnlistment         enlistment     = new MockEnlistment();
                MockHttpGitObjects     httpGitObjects = new MockHttpGitObjects(tracer, enlistment);
                MockPhysicalGitObjects gitObjects     = new MockPhysicalGitObjects(tracer, enlistment, httpGitObjects);

                BlockingCollection <string> input = new BlockingCollection <string>();
                input.Add(FakeSha);
                input.CompleteAdding();

                BatchObjectDownloadJob dut = new BatchObjectDownloadJob(1, 1, input, new BlockingCollection <string>(), tracer, enlistment, httpGitObjects, gitObjects);
                dut.Start();
                dut.WaitForCompletion();

                string sha;
                input.TryTake(out sha).ShouldEqual(false);

                IndexPackRequest request;
                dut.AvailablePacks.TryTake(out request).ShouldEqual(false);
            }
        }
示例#17
0
        public void TwoThreadsFailAtOnceStillRetriesOnce()
        {
            MockTracer     tracer     = new MockTracer();
            MockEnlistment enlistment = new MockEnlistment();
            MockGitProcess gitProcess = new MockGitProcess(enlistment);

            GitAuthentication dut = new GitAuthentication(gitProcess);

            string authString;
            string error;

            // Populate an initial PAT on two threads
            dut.TryGetCredentials(tracer, out authString, out error).ShouldEqual(true);
            dut.TryGetCredentials(tracer, out authString, out error).ShouldEqual(true);

            // Simulate a 401 error on two threads
            dut.RevokeAndCheckCanRetry(authString).ShouldEqual(true);
            dut.RevokeAndCheckCanRetry(authString).ShouldEqual(true, "The first thread is denying the second thread a chance to retry.");

            // Both threads should still be able to get a PAT for retry purposes
            dut.TryGetCredentials(tracer, out authString, out error).ShouldEqual(true, "The second thread caused back off when it shouldn't");
            dut.TryGetCredentials(tracer, out authString, out error).ShouldEqual(true);
        }
示例#18
0
 private CacheServerResolver CreateResolver(MockEnlistment enlistment = null)
 {
     enlistment = enlistment ?? this.CreateEnlistment();
     return(new CacheServerResolver(new MockTracer(), enlistment));
 }
示例#19
0
 private MockHttpGitObjects(MockEnlistment enlistment)
     : base(new MockTracer(), enlistment, new MockCacheServerInfo(), new RetryConfig(maxRetries: 1))
 {
 }