@@ -64,12 +64,12 @@ async fn do_test_internal<Out: test_logger::Output>(data: &[u8], _out: Out) {
64
64
65
65
let mut current_data = None ;
66
66
67
- let mut futures = Vec :: new ( ) ;
67
+ let mut handles = Vec :: new ( ) ;
68
68
loop {
69
69
let v = get_slice ! ( 1 ) [ 0 ] ;
70
- match v {
70
+ match v % 13 {
71
71
// Sync write
72
- 0x00 => {
72
+ 0 => {
73
73
let data_value = get_next_data_value ( ) ;
74
74
75
75
KVStoreSync :: write (
@@ -84,22 +84,22 @@ async fn do_test_internal<Out: test_logger::Output>(data: &[u8], _out: Out) {
84
84
current_data = Some ( data_value) ;
85
85
} ,
86
86
// Sync remove
87
- 0x01 => {
87
+ 1 => {
88
88
KVStoreSync :: remove ( fs_store, primary_namespace, secondary_namespace, key, false )
89
89
. unwrap ( ) ;
90
90
91
91
current_data = None ;
92
92
} ,
93
93
// Sync list
94
- 0x02 => {
94
+ 2 => {
95
95
KVStoreSync :: list ( fs_store, primary_namespace, secondary_namespace) . unwrap ( ) ;
96
96
} ,
97
97
// Sync read
98
- 0x03 => {
98
+ 3 => {
99
99
_ = KVStoreSync :: read ( fs_store, primary_namespace, secondary_namespace, key) ;
100
100
} ,
101
101
// Async write
102
- 0x04 => {
102
+ 4 ..= 9 => {
103
103
let data_value = get_next_data_value ( ) ;
104
104
105
105
let fut = KVStore :: write (
@@ -114,30 +114,41 @@ async fn do_test_internal<Out: test_logger::Output>(data: &[u8], _out: Out) {
114
114
// ordering semantics.
115
115
current_data = Some ( data_value) ;
116
116
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) ;
122
121
} ,
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
+ ) ;
129
131
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 ;
131
135
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
+ }
133
144
} ,
134
145
_ => {
135
146
return ;
136
147
} ,
137
148
}
138
149
139
150
// 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 ( ) {
141
152
let data_value =
142
153
KVStoreSync :: read ( fs_store, primary_namespace, secondary_namespace, key) . ok ( ) ;
143
154
assert_eq ! ( data_value, current_data) ;
0 commit comments