@@ -222,6 +222,15 @@ pub trait Connection: Send + Sync {
222222 benchmark_set : u32 ,
223223 ) -> anyhow:: Result < ( ) > ;
224224
225+ /// Add the confiuguration for a collector
226+ async fn add_collector_config (
227+ & self ,
228+ collector_name : & str ,
229+ target : & Target ,
230+ benchmark_set : u32 ,
231+ is_active : bool ,
232+ ) -> anyhow:: Result < CollectorConfig > ;
233+
225234 /// Get the confiuguration for a collector by the name of the collector
226235 async fn get_collector_config ( & self , collector_name : & str ) -> anyhow:: Result < CollectorConfig > ;
227236
@@ -652,6 +661,27 @@ mod tests {
652661 . await ;
653662 }
654663
664+ #[ tokio:: test]
665+ async fn add_collector_config ( ) {
666+ run_postgres_test ( |ctx| async {
667+ let db = ctx. db_client ( ) . connection ( ) . await ;
668+
669+ let insert_config_result = db
670+ . add_collector_config ( "collector-1" , & Target :: X86_64UnknownLinuxGnu , 1 , true )
671+ . await ;
672+ assert ! ( insert_config_result. is_ok( ) ) ;
673+
674+ let get_config_result = db. get_collector_config ( "collector-1" ) . await ;
675+ assert ! ( get_config_result. is_ok( ) ) ;
676+
677+ // What we entered into the database should be identical to what is
678+ // returned from the database
679+ assert_eq ! ( insert_config_result. unwrap( ) , get_config_result. unwrap( ) ) ;
680+ Ok ( ctx)
681+ } )
682+ . await ;
683+ }
684+
655685 #[ tokio:: test]
656686 async fn dequeue_benchmark_job_empty_queue ( ) {
657687 run_postgres_test ( |ctx| async {
@@ -672,4 +702,70 @@ mod tests {
672702 } )
673703 . await ;
674704 }
705+
706+ #[ tokio:: test]
707+ async fn dequeue_benchmark_job ( ) {
708+ run_postgres_test ( |ctx| async {
709+ let db = ctx. db_client ( ) . connection ( ) . await ;
710+ let time = chrono:: DateTime :: from_str ( "2021-09-01T00:00:00.000Z" ) . unwrap ( ) ;
711+
712+ let insert_result = db
713+ . add_collector_config ( "collector-1" , & Target :: X86_64UnknownLinuxGnu , 1 , true )
714+ . await ;
715+ assert ! ( insert_result. is_ok( ) ) ;
716+
717+ let collector_config = insert_result. unwrap ( ) ;
718+
719+ let benchmark_request =
720+ BenchmarkRequest :: create_master ( "sha-1" , "parent-sha-1" , 42 , time) ;
721+
722+ // Insert the request so we don't violate the foreign key
723+ db. insert_benchmark_request ( & benchmark_request)
724+ . await
725+ . unwrap ( ) ;
726+
727+ // Now we can insert the job
728+ let enqueue_result = db
729+ . enqueue_benchmark_job (
730+ benchmark_request. tag ( ) . unwrap ( ) ,
731+ & Target :: X86_64UnknownLinuxGnu ,
732+ & CodegenBackend :: Llvm ,
733+ & Profile :: Opt ,
734+ 1u32 ,
735+ )
736+ . await ;
737+ assert ! ( enqueue_result. is_ok( ) ) ;
738+
739+ let benchmark_job = db
740+ . dequeue_benchmark_job (
741+ collector_config. name ( ) ,
742+ collector_config. target ( ) ,
743+ collector_config. benchmark_set ( ) ,
744+ )
745+ . await ;
746+ assert ! ( benchmark_job. is_ok( ) ) ;
747+
748+ let benchmark_job = benchmark_job. unwrap ( ) ;
749+ assert ! ( benchmark_job. is_some( ) ) ;
750+
751+ // Ensure the properties of the job match both the request and the
752+ // collector configuration
753+ let benchmark_job = benchmark_job. unwrap ( ) ;
754+ assert_eq ! (
755+ benchmark_job. request_tag( ) ,
756+ benchmark_request. tag( ) . unwrap( )
757+ ) ;
758+ assert_eq ! (
759+ benchmark_job. benchmark_set( ) ,
760+ collector_config. benchmark_set( )
761+ ) ;
762+ assert_eq ! (
763+ benchmark_job. collector_name( ) . unwrap( ) ,
764+ collector_config. name( ) ,
765+ ) ;
766+
767+ Ok ( ctx)
768+ } )
769+ . await ;
770+ }
675771}
0 commit comments