@@ -234,6 +234,15 @@ pub trait Connection: Send + Sync {
234234 artifact_row_id : & ArtifactIdNumber ,
235235 ) -> anyhow:: Result < HashSet < CompileTestCase > > ;
236236
237+ /// Add the confiuguration for a collector
238+ async fn add_collector_config (
239+ & self ,
240+ collector_name : & str ,
241+ target : & Target ,
242+ benchmark_set : u32 ,
243+ is_active : bool ,
244+ ) -> anyhow:: Result < CollectorConfig > ;
245+
237246 /// Get the confiuguration for a collector by the name of the collector
238247 async fn get_collector_config ( & self , collector_name : & str ) -> anyhow:: Result < CollectorConfig > ;
239248
@@ -720,6 +729,27 @@ mod tests {
720729 . await ;
721730 }
722731
732+ #[ tokio:: test]
733+ async fn add_collector_config ( ) {
734+ run_postgres_test ( |ctx| async {
735+ let db = ctx. db_client ( ) . connection ( ) . await ;
736+
737+ let insert_config_result = db
738+ . add_collector_config ( "collector-1" , & Target :: X86_64UnknownLinuxGnu , 1 , true )
739+ . await ;
740+ assert ! ( insert_config_result. is_ok( ) ) ;
741+
742+ let get_config_result = db. get_collector_config ( "collector-1" ) . await ;
743+ assert ! ( get_config_result. is_ok( ) ) ;
744+
745+ // What we entered into the database should be identical to what is
746+ // returned from the database
747+ assert_eq ! ( insert_config_result. unwrap( ) , get_config_result. unwrap( ) ) ;
748+ Ok ( ctx)
749+ } )
750+ . await ;
751+ }
752+
723753 #[ tokio:: test]
724754 async fn dequeue_benchmark_job_empty_queue ( ) {
725755 run_postgres_test ( |ctx| async {
@@ -740,4 +770,70 @@ mod tests {
740770 } )
741771 . await ;
742772 }
773+
774+ #[ tokio:: test]
775+ async fn dequeue_benchmark_job ( ) {
776+ run_postgres_test ( |ctx| async {
777+ let db = ctx. db_client ( ) . connection ( ) . await ;
778+ let time = chrono:: DateTime :: from_str ( "2021-09-01T00:00:00.000Z" ) . unwrap ( ) ;
779+
780+ let insert_result = db
781+ . add_collector_config ( "collector-1" , & Target :: X86_64UnknownLinuxGnu , 1 , true )
782+ . await ;
783+ assert ! ( insert_result. is_ok( ) ) ;
784+
785+ let collector_config = insert_result. unwrap ( ) ;
786+
787+ let benchmark_request =
788+ BenchmarkRequest :: create_master ( "sha-1" , "parent-sha-1" , 42 , time) ;
789+
790+ // Insert the request so we don't violate the foreign key
791+ db. insert_benchmark_request ( & benchmark_request)
792+ . await
793+ . unwrap ( ) ;
794+
795+ // Now we can insert the job
796+ let enqueue_result = db
797+ . enqueue_benchmark_job (
798+ benchmark_request. tag ( ) . unwrap ( ) ,
799+ & Target :: X86_64UnknownLinuxGnu ,
800+ & CodegenBackend :: Llvm ,
801+ & Profile :: Opt ,
802+ 1u32 ,
803+ )
804+ . await ;
805+ assert ! ( enqueue_result. is_ok( ) ) ;
806+
807+ let benchmark_job = db
808+ . dequeue_benchmark_job (
809+ collector_config. name ( ) ,
810+ collector_config. target ( ) ,
811+ collector_config. benchmark_set ( ) ,
812+ )
813+ . await ;
814+ assert ! ( benchmark_job. is_ok( ) ) ;
815+
816+ let benchmark_job = benchmark_job. unwrap ( ) ;
817+ assert ! ( benchmark_job. is_some( ) ) ;
818+
819+ // Ensure the properties of the job match both the request and the
820+ // collector configuration
821+ let benchmark_job = benchmark_job. unwrap ( ) ;
822+ assert_eq ! (
823+ benchmark_job. request_tag( ) ,
824+ benchmark_request. tag( ) . unwrap( )
825+ ) ;
826+ assert_eq ! (
827+ benchmark_job. benchmark_set( ) ,
828+ collector_config. benchmark_set( )
829+ ) ;
830+ assert_eq ! (
831+ benchmark_job. collector_name( ) . unwrap( ) ,
832+ collector_config. name( ) ,
833+ ) ;
834+
835+ Ok ( ctx)
836+ } )
837+ . await ;
838+ }
743839}
0 commit comments