@@ -22,43 +22,44 @@ 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 ( NodeGit . THREAD_SAFETY . ENABLED ,
29+ NodeGit . getThreadSafetyStatus ( ) ) ;
2930
30- NodeGit . disableThreadSafety ( ) ;
31- assert . equal ( false , NodeGit . isThreadSafetyEnabled ( ) ) ;
31+ NodeGit . setThreadSafetyStatus ( NodeGit . THREAD_SAFETY . ENABLED_FOR_ASYNC_ONLY ) ;
32+ assert . equal ( NodeGit . THREAD_SAFETY . ENABLED_FOR_ASYNC_ONLY ,
33+ NodeGit . getThreadSafetyStatus ( ) ) ;
3234
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 ( ) ) ;
35+ NodeGit . setThreadSafetyStatus ( NodeGit . THREAD_SAFETY . DISABLED ) ;
36+ assert . equal ( NodeGit . THREAD_SAFETY . DISABLED ,
37+ NodeGit . getThreadSafetyStatus ( ) ) ;
3738
38- if ( originalValue ) {
39- NodeGit . enableThreadSafety ( ) ;
40- } else {
41- NodeGit . disableThreadSafety ( ) ;
42- }
39+ NodeGit . setThreadSafetyStatus ( originalValue ) ;
4340 } ) ;
4441
4542 it ( "can lock something and cleanup mutex" , function ( ) {
43+ var diagnostics = NodeGit . getThreadSafetyDiagnostics ( ) ;
44+ var originalCount = diagnostics . storedMutexesCount ;
4645 // call a sync method to guarantee that it stores a mutex,
4746 // and that it will clean up the mutex in a garbage collection cycle
4847 this . repository . headDetached ( ) ;
4948
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 ) ;
49+ diagnostics = NodeGit . getThreadSafetyDiagnostics ( ) ;
50+ switch ( NodeGit . getThreadSafetyStatus ( ) ) {
51+ case NodeGit . THREAD_SAFETY . ENABLED :
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+ break ;
57+ case NodeGit . THREAD_SAFETY . ENABLED_FOR_ASYNC_ONLY :
58+ assert . equal ( originalCount , diagnostics . storedMutexesCount ) ;
59+ break ;
60+
61+ case NodeGit . THREAD_SAFETY . DISABLED :
62+ assert . equal ( 0 , diagnostics . storedMutexesCount ) ;
6263 }
6364 } ) ;
6465} ) ;
0 commit comments