@@ -64,12 +64,12 @@ async fn do_test_internal<Out: test_logger::Output>(data: &[u8], _out: Out) {
6464
6565 let mut current_data = None ;
6666
67- let mut futures = Vec :: new ( ) ;
67+ let mut handles = Vec :: new ( ) ;
6868 loop {
6969 let v = get_slice ! ( 1 ) [ 0 ] ;
70- match v {
70+ match v % 13 {
7171 // Sync write
72- 0x00 => {
72+ 0 => {
7373 let data_value = get_next_data_value ( ) ;
7474
7575 KVStoreSync :: write (
@@ -84,22 +84,22 @@ async fn do_test_internal<Out: test_logger::Output>(data: &[u8], _out: Out) {
8484 current_data = Some ( data_value) ;
8585 } ,
8686 // Sync remove
87- 0x01 => {
87+ 1 => {
8888 KVStoreSync :: remove ( fs_store, primary_namespace, secondary_namespace, key, false )
8989 . unwrap ( ) ;
9090
9191 current_data = None ;
9292 } ,
9393 // Sync list
94- 0x02 => {
94+ 2 => {
9595 KVStoreSync :: list ( fs_store, primary_namespace, secondary_namespace) . unwrap ( ) ;
9696 } ,
9797 // Sync read
98- 0x03 => {
98+ 3 => {
9999 _ = KVStoreSync :: read ( fs_store, primary_namespace, secondary_namespace, key) ;
100100 } ,
101101 // Async write
102- 0x04 => {
102+ 4 ..= 9 => {
103103 let data_value = get_next_data_value ( ) ;
104104
105105 let fut = KVStore :: write (
@@ -114,30 +114,41 @@ async fn do_test_internal<Out: test_logger::Output>(data: &[u8], _out: Out) {
114114 // ordering semantics.
115115 current_data = Some ( data_value) ;
116116
117- // Store the future for later completion.
118- futures. push ( fut) ;
119- if futures. len ( ) > 10 {
120- return ;
121- }
117+ let handle = tokio:: task:: spawn ( fut) ;
118+
119+ // Store the handle to later await the result.
120+ handles. push ( handle) ;
122121 } ,
123- // Async write completion
124- 0x10 ..=0x19 => {
125- let fut_idx = ( v - 0x10 ) as usize ;
126- if fut_idx >= futures. len ( ) {
127- return ;
128- }
122+ // Async remove
123+ 10 | 11 => {
124+ let fut = KVStore :: remove (
125+ fs_store,
126+ primary_namespace,
127+ secondary_namespace,
128+ key,
129+ v == 10 ,
130+ ) ;
129131
130- let fut = futures. remove ( fut_idx) ;
132+ // Already set the current_data, even though writing hasn't finished yet. This supports the call-time
133+ // ordering semantics.
134+ current_data = None ;
131135
132- fut. await . unwrap ( ) ;
136+ let handle = tokio:: task:: spawn ( fut) ;
137+ handles. push ( handle) ;
138+ } ,
139+ // Join tasks.
140+ 12 => {
141+ for handle in handles. drain ( ..) {
142+ let _ = handle. await . unwrap ( ) ;
143+ }
133144 } ,
134145 _ => {
135146 return ;
136147 } ,
137148 }
138149
139150 // If no more writes are pending, we can reliably see if the data is consistent.
140- if futures . is_empty ( ) {
151+ if handles . is_empty ( ) {
141152 let data_value =
142153 KVStoreSync :: read ( fs_store, primary_namespace, secondary_namespace, key) . ok ( ) ;
143154 assert_eq ! ( data_value, current_data) ;
0 commit comments