@@ -13,7 +13,6 @@ use linera_base::{
1313 data_types:: Amount ,
1414} ;
1515use linera_execution:: ResourceControlPolicy ;
16- use tempfile:: { tempdir, TempDir } ;
1716use tokio:: process:: Command ;
1817#[ cfg( with_testing) ]
1918use {
@@ -49,6 +48,7 @@ pub struct LocalKubernetesNetConfig {
4948 pub no_build : bool ,
5049 pub docker_image_name : String ,
5150 pub policy : ResourceControlPolicy ,
51+ pub path_provider : PathProvider ,
5252}
5353
5454/// A wrapper of [`LocalKubernetesNetConfig`] to create a shared local Kubernetes network
@@ -62,14 +62,14 @@ pub struct LocalKubernetesNet {
6262 network : Network ,
6363 testing_prng_seed : Option < u64 > ,
6464 next_client_id : usize ,
65- tmp_dir : Arc < TempDir > ,
6665 binaries : BuildArg ,
6766 no_build : bool ,
6867 docker_image_name : String ,
6968 kubectl_instance : Arc < Mutex < KubectlInstance > > ,
7069 kind_clusters : Vec < KindCluster > ,
7170 num_initial_validators : usize ,
7271 num_shards : usize ,
72+ path_provider : PathProvider ,
7373}
7474
7575#[ cfg( with_testing) ]
@@ -92,6 +92,7 @@ impl SharedLocalKubernetesNetTestingConfig {
9292 binaries = BuildArg :: Directory ( binaries_dir) ;
9393 }
9494 }
95+ let path_provider = PathProvider :: create_temporary_directory ( ) . unwrap ( ) ;
9596 Self ( LocalKubernetesNetConfig {
9697 network,
9798 testing_prng_seed : Some ( 37 ) ,
@@ -103,6 +104,7 @@ impl SharedLocalKubernetesNetTestingConfig {
103104 no_build : false ,
104105 docker_image_name : String :: from ( "linera:latest" ) ,
105106 policy : ResourceControlPolicy :: devnet ( ) ,
107+ path_provider,
106108 } )
107109 }
108110}
@@ -134,6 +136,7 @@ impl LineraNetConfig for LocalKubernetesNetConfig {
134136 clusters,
135137 self . num_initial_validators ,
136138 self . num_shards ,
139+ self . path_provider ,
137140 ) ?;
138141
139142 let client = net. make_client ( ) . await ;
@@ -257,11 +260,8 @@ impl LineraNet for LocalKubernetesNet {
257260 }
258261
259262 async fn make_client ( & mut self ) -> ClientWrapper {
260- let path_provider = PathProvider :: TemporaryDirectory {
261- tmp_dir : self . tmp_dir . clone ( ) ,
262- } ;
263263 let client = ClientWrapper :: new (
264- path_provider,
264+ self . path_provider . clone ( ) ,
265265 self . network ,
266266 self . testing_prng_seed ,
267267 self . next_client_id ,
@@ -319,32 +319,36 @@ impl LocalKubernetesNet {
319319 kind_clusters : Vec < KindCluster > ,
320320 num_initial_validators : usize ,
321321 num_shards : usize ,
322+ path_provider : PathProvider ,
322323 ) -> Result < Self > {
323324 Ok ( Self {
324325 network,
325326 testing_prng_seed,
326327 next_client_id : 0 ,
327- tmp_dir : Arc :: new ( tempdir ( ) ?) ,
328328 binaries,
329329 no_build,
330330 docker_image_name,
331331 kubectl_instance : Arc :: new ( Mutex :: new ( kubectl_instance) ) ,
332332 kind_clusters,
333333 num_initial_validators,
334334 num_shards,
335+ path_provider,
335336 } )
336337 }
337338
338339 async fn command_for_binary ( & self , name : & ' static str ) -> Result < Command > {
339340 let path = resolve_binary ( name, env ! ( "CARGO_PKG_NAME" ) ) . await ?;
340341 let mut command = Command :: new ( path) ;
341- command. current_dir ( self . tmp_dir . path ( ) ) ;
342+ command. current_dir ( self . path_provider . path ( ) ) ;
342343 Ok ( command)
343344 }
344345
345346 fn configuration_string ( & self , server_number : usize ) -> Result < String > {
346347 let n = server_number;
347- let path = self . tmp_dir . path ( ) . join ( format ! ( "validator_{n}.toml" ) ) ;
348+ let path = self
349+ . path_provider
350+ . path ( )
351+ . join ( format ! ( "validator_{n}.toml" ) ) ;
348352 let port = 19100 + server_number;
349353 let internal_port = 20100 ;
350354 let metrics_port = 21100 ;
@@ -418,13 +422,11 @@ impl LocalKubernetesNet {
418422 . join ( "kubernetes" )
419423 . join ( "linera-validator" )
420424 . join ( "working" ) ;
421- fs_err:: copy (
422- self . tmp_dir . path ( ) . join ( "genesis.json" ) ,
423- base_dir. join ( "genesis.json" ) ,
424- ) ?;
425+ let path = self . path_provider . path ( ) ;
426+ fs_err:: copy ( path. join ( "genesis.json" ) , base_dir. join ( "genesis.json" ) ) ?;
425427
426428 let kubectl_instance_clone = self . kubectl_instance . clone ( ) ;
427- let tmp_dir_path_clone = self . tmp_dir . path ( ) . to_path_buf ( ) ;
429+ let tmp_dir_path_clone = path. to_path_buf ( ) ;
428430 let num_shards = self . num_shards ;
429431
430432 let mut validators_initialization_futures = Vec :: new ( ) ;
0 commit comments