@@ -42,49 +42,52 @@ mod tests {
4242
4343 #[ test]
4444 fn test_paxos ( ) -> anyhow:: Result < ( ) > {
45- //
46-
4745 let ex = Arc :: new ( Executor :: new ( ) ) ;
4846
49- let fu = do_test ( ex. clone ( ) ) ;
47+ let fu = async move {
48+ let acceptor_ids = [ 1 , 2 , 3 ] ;
5049
51- futures_lite:: future:: block_on ( ex. run ( fu) ) ?;
52- Ok ( ( ) )
50+ let mut acceptors = BTreeMap :: new ( ) ;
51+ for id in acceptor_ids {
52+ acceptors. insert ( id, Acceptor :: default ( ) ) ;
53+ }
5354
54- // TODO: rebuild from previous value
55- }
55+ let quorum_set = Majority :: new ( acceptor_ids ) ;
56+ let transport = DirectCall :: new ( acceptors . clone ( ) ) ;
5657
57- async fn do_test ( ex : Arc < Executor < ' _ > > ) -> anyhow:: Result < ( ) > {
58- ex. spawn ( async {
59- println ! ( "Inner task" ) ;
60- } )
61- . detach ( ) ;
58+ let mut apaxos = APaxos :: < Paxos > :: new ( acceptor_ids, quorum_set, transport) ;
6259
63- let acceptor_ids = [ 1 , 2 , 3 ] ;
60+ let mut proposer = Proposer :: new ( & mut apaxos , 5 , "hello" . to_string ( ) ) ;
6461
65- let mut acceptors = BTreeMap :: new ( ) ;
66- for id in acceptor_ids {
67- acceptors. insert ( id, Acceptor :: default ( ) ) ;
68- }
62+ let committed = proposer. run ( ) . await ?;
6963
70- let quorum_set = Majority :: new ( acceptor_ids ) ;
71- let transport = DirectCall :: new ( acceptors . clone ( ) ) ;
64+ assert_eq ! ( committed . latest_time ( ) , Some ( 5 ) ) ;
65+ assert_eq ! ( committed . latest_value ( ) , Some ( s ( "hello" ) ) ) ;
7266
73- let mut apaxos = APaxos :: < Paxos > :: new ( acceptor_ids , quorum_set , transport ) ;
67+ println ! ( "Done" ) ;
7468
75- let mut proposer = Proposer :: new ( & mut apaxos , 5 , "hello" . to_string ( ) ) ;
76- let committed = proposer . run ( ) . await ? ;
69+ Ok :: < ( ) , anyhow :: Error > ( ( ) )
70+ } ;
7771
78- assert_eq ! ( committed. latest_time( ) , Some ( 5 ) ) ;
79- assert_eq ! ( committed. latest_value( ) , Some ( s( "hello" ) ) ) ;
72+ // let mut proposer = Proposer::new(&mut apaxos, 6, "world".to_string());
73+ // let committed = proposer.run().await?;
74+ //
75+ // assert_eq!(committed.latest_time(), Some(6));
76+ // assert_eq!(committed.latest_value(), Some(s("hello")));
77+
78+ ex. spawn ( fu) . detach ( ) ;
8079
81- let mut proposer = Proposer :: new ( & mut apaxos , 6 , "world" . to_string ( ) ) ;
82- let committed = proposer . run ( ) . await ? ;
80+ futures_lite :: future :: block_on ( ex . tick ( ) ) ;
81+ Ok ( ( ) )
8382
84- assert_eq ! ( committed . latest_time ( ) , Some ( 6 ) ) ;
85- assert_eq ! ( committed . latest_value ( ) , Some ( s ( "hello" ) ) ) ;
83+ // TODO: rebuild from previous value
84+ }
8685
87- println ! ( "Done" ) ;
86+ async fn do_test ( ex : Arc < Executor < ' _ > > ) -> anyhow:: Result < ( ) > {
87+ ex. spawn ( async {
88+ println ! ( "Inner task" ) ;
89+ } )
90+ . detach ( ) ;
8891
8992 Ok ( ( ) )
9093 }
0 commit comments