예제 #1
0
        public TestData(string testName, ILogging logger, string serverDirectory)
        {
            TestName    = testName;
            Logger      = logger;
            Watch       = new Stopwatch();
            TestPath    = SPath.CreateTempDirectory(testName);
            TaskManager = new TaskManager();

            try
            {
                TaskManager.Initialize();
            }
            catch
            {
                // we're on the nunit sync context, which can't be used to create a task scheduler
                // so use a different context as the main thread. The test won't run on the main nunit thread
                ourContext = new MainThreadSynchronizationContext(TaskManager.Token);
                TaskManager.Initialize(ourContext);
            }

            Environment = new UnityEnvironment(testName);
            InitializeEnvironment();
            ProcessManager = new ProcessManager(Environment);
            Configuration  = new ServerConfiguration(serverDirectory);

            Logger.Trace($"START {testName}");
            Watch.Start();
        }
예제 #2
0
        private GitInstallationState ExtractGit(GitInstallationState state)
        {
            var tempZipExtractPath = SPath.CreateTempDirectory("ghu_extract_git");

            if (state.GitZipExists && !state.GitIsValid)
            {
                var gitExtractPath = tempZipExtractPath.Combine("git").CreateDirectory();
                var unzipTask      = new UnzipTask(TaskManager, state.GitZipPath,
                                                   gitExtractPath, sharpZipLibHelper)
                                     .Progress(progressReporter.UpdateProgress)
                                     .Catch(e =>
                {
                    Logger.Trace(e, "Failed to unzip " + state.GitZipPath);
                    return(true);
                });

                unzipTask.RunSynchronously();
                var target = state.GitInstallationPath;
                if (unzipTask.Successful)
                {
                    Logger.Trace("Moving Git source:{0} target:{1}", gitExtractPath.ToString(), target.ToString());

                    CopyHelper.Copy(gitExtractPath, target);

                    state.GitIsValid      = state.GitLfsIsValid = true;
                    state.IsCustomGitPath = state.GitExecutablePath != installDetails.GitExecutablePath;
                }
            }

            tempZipExtractPath.DeleteIfExists();
            return(state);
        }
예제 #3
0
        public TestData(string testName, ILogging logger, string testRepoName = null, bool withHttpServer = false,
                        ICacheContainer cacheContainer = null,
                        IFileSystem fileSystem         = null)
        {
            TestName         = testName;
            Logger           = logger;
            Watch            = new Stopwatch();
            SourceDirectory  = TestContext.CurrentContext.TestDirectory.ToSPath();
            TestPath         = SPath.CreateTempDirectory(testName);
            SPath.FileSystem = fileSystem ?? new FileSystem(TestPath);

            if (cacheContainer == null)
            {
                var container = new CacheContainer();
                container.SetCacheInitializer(CacheType.Branches, () => BranchesCache.Instance);
                container.SetCacheInitializer(CacheType.GitAheadBehind, () => GitAheadBehindCache.Instance);
                container.SetCacheInitializer(CacheType.GitLocks, () => GitLocksCache.Instance);
                container.SetCacheInitializer(CacheType.GitLog, () => GitLogCache.Instance);
                container.SetCacheInitializer(CacheType.GitStatus, () => GitStatusCache.Instance);
                container.SetCacheInitializer(CacheType.GitUser, () => GitUserCache.Instance);
                container.SetCacheInitializer(CacheType.RepositoryInfo, () => RepositoryInfoCache.Instance);
                cacheContainer = container;
            }


            Environment = new IntegrationTestEnvironment(cacheContainer, TestPath, TestPath.Parent, testName);
            InitializeEnvironment(testRepoName);

            ApplicationManager = new ApplicationManagerBase(new MainThreadSynchronizationContext(), Environment);

            if (testRepoName != null)
            {
                var testZipFilePath = SourceDirectory.Combine("IOTestsRepo.zip");
                ZipHelper.Instance.Extract(testZipFilePath, TestPath, (_, __) => { }, (value, total, name) => true, token: TaskManager.Token);
                TestRepo = new TestRepoData(this, testRepoName);

                InstallTestGit();
                InitializeRepository();
            }

#if NUNIT
            if (withHttpServer)
            {
                var filesToServePath = SourceDirectory.Combine("files");
                HttpServer = new HttpServer(filesToServePath, 0);
                var started = new ManualResetEventSlim();
                var task    = TaskManager.With(HttpServer.Start, TaskAffinity.None);
                task.OnStart += _ => started.Set();
                task.Start();
                started.Wait();
            }
#endif
            ((ApplicationManagerBase)ApplicationManager).Initialize();

            Logger.Trace($"START {testName}");
            Watch.Start();
        }
예제 #4
0
        public TestData(string testName, ILogging logger, bool withHttpServer = false)
        {
            TestName        = testName;
            Logger          = logger;
            Watch           = new Stopwatch();
            SourceDirectory = TestContext.CurrentContext.TestDirectory.ToSPath();
            TestPath        = SPath.CreateTempDirectory(testName);
            TaskManager     = new TaskManager();
            cts             = CancellationTokenSource.CreateLinkedTokenSource(TaskManager.Token);

            try
            {
                TaskManager.Initialize();
            }
            catch
            {
                // we're on the nunit sync context, which can't be used to create a task scheduler
                // so use a different context as the main thread. The test won't run on the main nunit thread
                TaskManager.Initialize(new MainThreadSynchronizationContext(cts.Token));
            }

            Environment = new UnityEnvironment(testName);
            InitializeEnvironment();
            ProcessManager = new ProcessManager(Environment);

#if NUNIT
            if (withHttpServer)
            {
                var filesToServePath = SourceDirectory.Combine("files");
                HttpServer = new HttpServer(filesToServePath, 0);
                var started = new ManualResetEventSlim();
                var task    = TaskManager.With(HttpServer.Start, TaskAffinity.None);
                task.OnStart += _ => started.Set();
                task.Start();
                started.Wait();
            }
#endif

            Logger.Trace($"START {testName}");
            Watch.Start();
        }
예제 #5
0
        public bool Extract(string archive, string outFolder, CancellationToken cancellationToken,
                            Action <string, long> onStart, Func <long, long, string, bool> onProgress, Func <string, bool> onFilter = null)
        {
            var destDir = outFolder.ToSPath();

            destDir.EnsureDirectoryExists();
            if (archive.EndsWith(".tar.gz"))
            {
                var gzipFile = archive.ToSPath();

                archive = SPath.CreateTempDirectory("git").Combine(gzipFile.FileNameWithoutExtension);
                using (var instream = SPath.FileSystem.OpenRead(gzipFile))
                    using (var outstream = SPath.FileSystem.OpenWrite(archive, FileMode.CreateNew))
                    {
                        GZip.Decompress(instream, outstream, false);
                    }
            }

            if (archive.EndsWith(".tar"))
            {
                return(ExtractTar(archive, destDir, cancellationToken, onStart, onProgress, onFilter));
            }
            return(ExtractZip(archive, destDir, cancellationToken, onStart, onProgress, onFilter));
        }