2020-03-04 12:49:36 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								/ * *  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  @license 
							 
						 
					
						
							
								
									
										
										
										
											2020-05-19 12:08:49 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								 *  Copyright  Google  LLC  All  Rights  Reserved . 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-04 12:49:36 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  Use  of  this  source  code  is  governed  by  an  MIT - style  license  that  can  be 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  found  in  the  LICENSE  file  at  https : //angular.io/license
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 * / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  { getFileSystem }  from  '../../../src/ngtsc/file_system' ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  { runInEachFileSystem }  from  '../../../src/ngtsc/file_system/testing' ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  { SyncLocker }  from  '../../src/locking/sync_locker' ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  { MockLockFile }  from  '../helpers/mock_lock_file' ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								runInEachFileSystem ( ( )  = >  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  describe ( 'SyncLocker' ,  ( )  = >  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    describe ( 'lock()' ,  ( )  = >  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      it ( 'should guard the `fn()` with calls to `write()` and `remove()`' ,  ( )  = >  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  fs  =  getFileSystem ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  log : string [ ]  =  [ ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  lockFile  =  new  MockLockFile ( fs ,  log ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  locker  =  new  SyncLocker ( lockFile ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        locker . lock ( ( )  = >  log . push ( 'fn()' ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        expect ( log ) . toEqual ( [ 'write()' ,  'fn()' ,  'remove()' ] ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      it ( 'should guard the `fn()` with calls to `write()` and `remove()`, even if it throws' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								         ( )  = >  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								           let  error : string  =  '' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								           const  fs  =  getFileSystem ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								           const  log : string [ ]  =  [ ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								           const  lockFile  =  new  MockLockFile ( fs ,  log ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								           const  locker  =  new  SyncLocker ( lockFile ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								           try  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								             locker . lock ( ( )  = >  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								               log . push ( 'fn()' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								               throw  new  Error ( 'ERROR' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								             } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								           }  catch  ( e )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								             error  =  e . message ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								           } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								           expect ( error ) . toEqual ( 'ERROR' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								           expect ( log ) . toEqual ( [ 'write()' ,  'fn()' ,  'remove()' ] ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								         } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      it ( 'should error if a lock file already exists' ,  ( )  = >  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  fs  =  getFileSystem ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  log : string [ ]  =  [ ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  lockFile  =  new  MockLockFile ( fs ,  log ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  locker  =  new  SyncLocker ( lockFile ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-04-06 08:30:08 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        spyOn ( lockFile ,  'write' ) . and . callFake ( ( )  = >  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          throw  { code :  'EEXIST' } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-04 12:49:36 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        spyOn ( lockFile ,  'read' ) . and . returnValue ( '188' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        expect ( ( )  = >  locker . lock ( ( )  = >  { } ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            . toThrowError ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                ` ngcc is already running at process with id 188. \ n `  + 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                ` If you are running multiple builds in parallel then you should pre-process your node_modules via the command line ngcc tool before starting the builds; \ n `  + 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                ` See https://v9.angular.io/guide/ivy#speeding-up-ngcc-compilation. \ n `  + 
							 
						 
					
						
							
								
									
										
										
										
											2020-04-06 08:30:08 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                ` (If you are sure no ngcc process is running then you should delete the lock-file at  ${ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    lockFile . path } . ) ` );
 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-04 12:49:36 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								      } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ) ;