4141)
4242from  chia_rs .sized_bytes  import  bytes32 
4343from  chia_rs .sized_ints  import  uint8 , uint16 , uint32 , uint64 , uint128 
44+ from  filelock  import  FileLock 
4445
4546from  chia .consensus .block_creation  import  create_unfinished_block , unfinished_block_to_full_block 
4647from  chia .consensus .block_record  import  BlockRecordProtocol 
@@ -338,6 +339,29 @@ def test_callback(event: PlotRefreshEvents, update_result: PlotRefreshResult) ->
338339                assert  self .total_result .processed  ==  update_result .processed 
339340                assert  self .total_result .duration  ==  update_result .duration 
340341                assert  update_result .remaining  ==  0 
342+ 
343+                 expected_plots : set [str ] =  set ()
344+                 found_plots : set [str ] =  set ()
345+                 if  len (self .plot_manager .plots ) !=  len (self .expected_plots ):  # pragma: no cover 
346+                     for  pid , filename  in  self .expected_plots .items ():
347+                         expected_plots .add (filename .name )
348+                     for  filename , _  in  self .plot_manager .plots .items ():
349+                         found_plots .add (filename .name )
350+                     print (f"directory: { self .plot_dir }  " )
351+                     print (f"expected: { len (expected_plots )}  " )
352+                     for  f  in  expected_plots :
353+                         print (f )
354+                     print (f"plot manager: { len (found_plots )}  " )
355+                     for  f  in  found_plots :
356+                         print (f )
357+                     diff  =  found_plots .difference (expected_plots )
358+                     print (f"found unexpected: { len (diff )}  " )
359+                     for  f  in  diff :
360+                         print (f )
361+                     diff  =  expected_plots .difference (found_plots )
362+                     print (f"not found: { len (diff )}  " )
363+                     for  f  in  diff :
364+                         print (f )
341365                assert  len (self .plot_manager .plots ) ==  len (self .expected_plots )
342366
343367        self .plot_manager : PlotManager  =  PlotManager (
@@ -500,34 +524,41 @@ async def setup_plots(
500524        num_non_keychain_plots : int  =  3 ,
501525        plot_size : int  =  20 ,
502526        bitfield : bool  =  True ,
527+         testrun_uid : Optional [str ] =  None ,
503528    ) ->  bool :
504-         self .add_plot_directory (self .plot_dir )
505-         assert  self .created_plots  ==  0 
506-         existing_plots : bool  =  True 
507-         # OG Plots 
508-         for  i  in  range (num_og_plots ):
509-             plot  =  await  self .new_plot (plot_size = plot_size , bitfield = bitfield )
510-             if  plot .new_plot :
511-                 existing_plots  =  False 
512-         # Pool Plots 
513-         for  i  in  range (num_pool_plots ):
514-             plot  =  await  self .new_plot (self .pool_ph , plot_size = plot_size , bitfield = bitfield )
515-             if  plot .new_plot :
516-                 existing_plots  =  False 
517-         # Some plots with keys that are not in the keychain 
518-         for  i  in  range (num_non_keychain_plots ):
519-             plot  =  await  self .new_plot (
520-                 path = self .plot_dir  /  "not_in_keychain" ,
521-                 plot_keys = PlotKeys (G1Element (), G1Element (), None ),
522-                 exclude_plots = True ,
523-                 plot_size = plot_size ,
524-                 bitfield = bitfield ,
525-             )
526-             if  plot .new_plot :
527-                 existing_plots  =  False 
528-         await  self .refresh_plots ()
529-         assert  len (self .plot_manager .plots ) ==  len (self .expected_plots )
530-         return  existing_plots 
529+         if  testrun_uid  is  None :
530+             lock_file_name  =  self .plot_dir  /  ".lockfile" 
531+         else :
532+             lock_file_name  =  self .plot_dir  /  (testrun_uid  +  ".lockfile" )
533+ 
534+         with  FileLock (lock_file_name ):
535+             self .add_plot_directory (self .plot_dir )
536+             assert  self .created_plots  ==  0 
537+             existing_plots : bool  =  True 
538+             # OG Plots 
539+             for  i  in  range (num_og_plots ):
540+                 plot  =  await  self .new_plot (plot_size = plot_size , bitfield = bitfield )
541+                 if  plot .new_plot :
542+                     existing_plots  =  False 
543+             # Pool Plots 
544+             for  i  in  range (num_pool_plots ):
545+                 plot  =  await  self .new_plot (self .pool_ph , plot_size = plot_size , bitfield = bitfield )
546+                 if  plot .new_plot :
547+                     existing_plots  =  False 
548+             # Some plots with keys that are not in the keychain 
549+             for  i  in  range (num_non_keychain_plots ):
550+                 plot  =  await  self .new_plot (
551+                     path = self .plot_dir  /  "not_in_keychain" ,
552+                     plot_keys = PlotKeys (G1Element (), G1Element (), None ),
553+                     exclude_plots = True ,
554+                     plot_size = plot_size ,
555+                     bitfield = bitfield ,
556+                 )
557+                 if  plot .new_plot :
558+                     existing_plots  =  False 
559+             await  self .refresh_plots ()
560+             assert  len (self .plot_manager .plots ) ==  len (self .expected_plots )
561+             return  existing_plots 
531562
532563    async  def  new_plot (
533564        self ,
@@ -2080,6 +2111,7 @@ async def create_block_tools_async(
20802111    num_og_plots : int  =  15 ,
20812112    num_pool_plots : int  =  5 ,
20822113    num_non_keychain_plots : int  =  3 ,
2114+     testrun_uid : Optional [str ] =  None ,
20832115) ->  BlockTools :
20842116    global  create_block_tools_async_count 
20852117    create_block_tools_async_count  +=  1 
@@ -2090,6 +2122,7 @@ async def create_block_tools_async(
20902122        num_og_plots = num_og_plots ,
20912123        num_pool_plots = num_pool_plots ,
20922124        num_non_keychain_plots = num_non_keychain_plots ,
2125+         testrun_uid = testrun_uid ,
20932126    )
20942127
20952128    return  bt 
0 commit comments