11using System ;
2+ using System . Diagnostics ;
23using NUnit . Framework ;
34using GitHub . Unity ;
45using NCrunch . Framework ;
56using System . Threading ;
67using GitHub . Logging ;
78using System . Linq ;
89using System . IO ;
10+ using System . Runtime . CompilerServices ;
911
1012namespace IntegrationTests
1113{
@@ -78,18 +80,19 @@ protected void InitializeEnvironment(NPath repoPath = null,
7880 initializeRepository ) ;
7981 }
8082
81- protected void InitializePlatform ( NPath repoPath , NPath environmentPath , bool enableEnvironmentTrace , bool initializeRepository = true , bool setupGit = true )
83+ private void InitializePlatform ( NPath repoPath , NPath environmentPath , bool enableEnvironmentTrace ,
84+ bool setupGit = true , string testName = "" )
8285 {
8386 InitializeTaskManager ( ) ;
84- InitializeEnvironment ( repoPath , environmentPath , enableEnvironmentTrace , initializeRepository ) ;
87+ InitializeEnvironment ( repoPath , environmentPath , enableEnvironmentTrace , true ) ;
8588
8689 Platform = new Platform ( Environment ) ;
8790 ProcessManager = new ProcessManager ( Environment , GitEnvironment , TaskManager . Token ) ;
8891
8992 Platform . Initialize ( ProcessManager , TaskManager ) ;
9093
9194 if ( setupGit )
92- SetupGit ( Environment . GetSpecialFolder ( System . Environment . SpecialFolder . LocalApplicationData ) . ToNPath ( ) ) ;
95+ SetupGit ( Environment . GetSpecialFolder ( System . Environment . SpecialFolder . LocalApplicationData ) . ToNPath ( ) , testName ) ;
9396 }
9497
9598 protected void InitializeTaskManager ( )
@@ -103,9 +106,10 @@ protected IEnvironment InitializePlatformAndEnvironment(NPath repoPath,
103106 NPath environmentPath = null ,
104107 bool enableEnvironmentTrace = false ,
105108 bool setupGit = true ,
106- Action < IRepositoryManager > onRepositoryManagerCreated = null )
109+ Action < IRepositoryManager > onRepositoryManagerCreated = null ,
110+ [ CallerMemberName ] string testName = "" )
107111 {
108- InitializePlatform ( repoPath , environmentPath , enableEnvironmentTrace , setupGit ) ;
112+ InitializePlatform ( repoPath , environmentPath , enableEnvironmentTrace , setupGit , testName ) ;
109113
110114 DotGitPath = repoPath . Combine ( ".git" ) ;
111115
@@ -133,15 +137,20 @@ protected IEnvironment InitializePlatformAndEnvironment(NPath repoPath,
133137 return Environment ;
134138 }
135139
136- protected void SetupGit ( NPath pathToSetupGitInto )
140+ protected void SetupGit ( NPath pathToSetupGitInto , string testName )
137141 {
138142 var autoResetEvent = new AutoResetEvent ( false ) ;
139143
140144 var installDetails = new GitInstaller . GitInstallDetails ( pathToSetupGitInto , true ) ;
141145
142146 var zipArchivesPath = pathToSetupGitInto . Combine ( "downloads" ) . CreateDirectory ( ) ;
147+
148+ Logger . Trace ( $ "Saving git zips into { zipArchivesPath } and unzipping to { pathToSetupGitInto } ") ;
149+
143150 AssemblyResources . ToFile ( ResourceType . Platform , "git.zip" , zipArchivesPath , Environment ) ;
151+ AssemblyResources . ToFile ( ResourceType . Platform , "git.zip.md5" , zipArchivesPath , Environment ) ;
144152 AssemblyResources . ToFile ( ResourceType . Platform , "git-lfs.zip" , zipArchivesPath , Environment ) ;
153+ AssemblyResources . ToFile ( ResourceType . Platform , "git-lfs.zip.md5" , zipArchivesPath , Environment ) ;
145154
146155 var gitInstaller = new GitInstaller ( Environment , TaskManager . Token , installDetails ) ;
147156
@@ -155,7 +164,8 @@ protected void SetupGit(NPath pathToSetupGitInto)
155164 autoResetEvent . Set ( ) ;
156165 } ;
157166
158- autoResetEvent . WaitOne ( ) ;
167+ if ( ! autoResetEvent . WaitOne ( TimeSpan . FromMinutes ( 1 ) ) )
168+ throw new TimeoutException ( $ "Test setup unzipping { zipArchivesPath } to { pathToSetupGitInto } timed out") ;
159169
160170 if ( result == null )
161171 {
@@ -220,5 +230,31 @@ public virtual void OnTearDown()
220230
221231 NPath . FileSystem = null ;
222232 }
233+
234+ protected void StartTest ( out Stopwatch watch , out ILogging logger , [ CallerMemberName ] string testName = "test" )
235+ {
236+ watch = new Stopwatch ( ) ;
237+ logger = LogHelper . GetLogger ( testName ) ;
238+ logger . Trace ( "Starting test" ) ;
239+ }
240+
241+ protected void EndTest ( ILogging logger )
242+ {
243+ logger . Trace ( "Ending test" ) ;
244+ }
245+
246+ protected void StartTrackTime ( Stopwatch watch , ILogging logger = null , string message = "" )
247+ {
248+ if ( ! String . IsNullOrEmpty ( message ) )
249+ logger . Trace ( message ) ;
250+ watch . Reset ( ) ;
251+ watch . Start ( ) ;
252+ }
253+
254+ protected void StopTrackTimeAndLog ( Stopwatch watch , ILogging logger )
255+ {
256+ watch . Stop ( ) ;
257+ logger . Trace ( $ "Time: { watch . ElapsedMilliseconds } ") ;
258+ }
223259 }
224260}
0 commit comments