@@ -22,43 +22,41 @@ describe("ThreadSafety", function() {
2222 } ) ;
2323
2424 it ( "can enable and disable thread safety" , function ( ) {
25- var originalValue = NodeGit . isThreadSafetyEnabled ( ) ;
25+ var originalValue = NodeGit . getThreadSafetyStatus ( ) ;
2626
2727 NodeGit . enableThreadSafety ( ) ;
28- assert . equal ( true , NodeGit . isThreadSafetyEnabled ( ) ) ;
28+ assert . equal ( 2 , NodeGit . getThreadSafetyStatus ( ) ) ;
2929
30- NodeGit . disableThreadSafety ( ) ;
31- assert . equal ( false , NodeGit . isThreadSafetyEnabled ( ) ) ;
30+ NodeGit . setThreadSafetyStatus ( 1 ) ;
31+ assert . equal ( 1 , NodeGit . getThreadSafetyStatus ( ) ) ;
3232
33- // flip the switch again, to make sure we test all transitions
34- // (we could have started with thread safety enabled)
35- NodeGit . enableThreadSafety ( ) ;
36- assert . equal ( true , NodeGit . isThreadSafetyEnabled ( ) ) ;
33+ NodeGit . setThreadSafetyStatus ( 0 ) ;
34+ assert . equal ( 0 , NodeGit . getThreadSafetyStatus ( ) ) ;
3735
38- if ( originalValue ) {
39- NodeGit . enableThreadSafety ( ) ;
40- } else {
41- NodeGit . disableThreadSafety ( ) ;
42- }
36+ NodeGit . setThreadSafetyStatus ( originalValue ) ;
4337 } ) ;
4438
4539 it ( "can lock something and cleanup mutex" , function ( ) {
40+ var diagnostics = NodeGit . getThreadSafetyDiagnostics ( ) ;
41+ var originalCount = diagnostics . storedMutexesCount ;
4642 // call a sync method to guarantee that it stores a mutex,
4743 // and that it will clean up the mutex in a garbage collection cycle
4844 this . repository . headDetached ( ) ;
4945
50- var diagnostics = NodeGit . getThreadSafetyDiagnostics ( ) ;
51- if ( NodeGit . isThreadSafetyEnabled ( ) ) {
52- // this is a fairly vague test - it just tests that something
53- // had a mutex created for it at some point (i.e., the thread safety
54- // code is not completely dead)
55- assert . ok ( diagnostics . storedMutexesCount > 0 ) ;
56- // now test that GC cleans up mutexes
57- global . gc ( ) ;
58- diagnostics = NodeGit . getThreadSafetyDiagnostics ( ) ;
59- assert . equal ( 0 , diagnostics . storedMutexesCount ) ;
60- } else {
61- assert . equal ( 0 , diagnostics . storedMutexesCount ) ;
46+ diagnostics = NodeGit . getThreadSafetyDiagnostics ( ) ;
47+ switch ( NodeGit . getThreadSafetyStatus ( ) ) {
48+ case 2 :
49+ // this is a fairly vague test - it just tests that something
50+ // had a mutex created for it at some point (i.e., the thread safety
51+ // code is not completely dead)
52+ assert . ok ( diagnostics . storedMutexesCount > 0 ) ;
53+ break ;
54+ case 1 :
55+ assert . equal ( originalCount , diagnostics . storedMutexesCount ) ;
56+ break ;
57+
58+ case 0 :
59+ assert . equal ( 0 , diagnostics . storedMutexesCount ) ;
6260 }
6361 } ) ;
6462} ) ;
0 commit comments