@@ -14,6 +14,7 @@ async fn test_sync_context_push_frame() {
14
14
let server = MockServer :: start ( ) ;
15
15
let temp_dir = tempdir ( ) . unwrap ( ) ;
16
16
let db_path = temp_dir. path ( ) . join ( "test.db" ) ;
17
+ gen_metadata_file ( & db_path, 3278479626 , 0 , 0 , 1 ) ;
17
18
18
19
let sync_ctx = SyncContext :: new (
19
20
server. connector ( ) ,
@@ -44,6 +45,7 @@ async fn test_sync_context_with_auth() {
44
45
let server = MockServer :: start ( ) ;
45
46
let temp_dir = tempdir ( ) . unwrap ( ) ;
46
47
let db_path = temp_dir. path ( ) . join ( "test.db" ) ;
48
+ gen_metadata_file ( & db_path, 3278479626 , 0 , 0 , 1 ) ;
47
49
48
50
let sync_ctx = SyncContext :: new (
49
51
server. connector ( ) ,
@@ -69,6 +71,7 @@ async fn test_sync_context_multiple_frames() {
69
71
let server = MockServer :: start ( ) ;
70
72
let temp_dir = tempdir ( ) . unwrap ( ) ;
71
73
let db_path = temp_dir. path ( ) . join ( "test.db" ) ;
74
+ gen_metadata_file ( & db_path, 3278479626 , 0 , 0 , 1 ) ;
72
75
73
76
let sync_ctx = SyncContext :: new (
74
77
server. connector ( ) ,
@@ -98,6 +101,7 @@ async fn test_sync_context_corrupted_metadata() {
98
101
let server = MockServer :: start ( ) ;
99
102
let temp_dir = tempdir ( ) . unwrap ( ) ;
100
103
let db_path = temp_dir. path ( ) . join ( "test.db" ) ;
104
+ gen_metadata_file ( & db_path, 3278479626 , 0 , 0 , 1 ) ;
101
105
102
106
// Create initial sync context and push a frame
103
107
let sync_ctx = SyncContext :: new (
@@ -129,12 +133,9 @@ async fn test_sync_context_corrupted_metadata() {
129
133
None ,
130
134
None ,
131
135
)
132
- . await
133
- . unwrap ( ) ;
136
+ . await ;
134
137
135
- // Verify that the context was reset to default values
136
- assert_eq ! ( sync_ctx. durable_frame_num( ) , 0 ) ;
137
- assert_eq ! ( sync_ctx. durable_generation( ) , 0 ) ;
138
+ assert ! ( sync_ctx. is_err( ) ) ;
138
139
}
139
140
140
141
#[ tokio:: test]
@@ -144,6 +145,7 @@ async fn test_sync_restarts_with_lower_max_frame_no() {
144
145
let server = MockServer :: start ( ) ;
145
146
let temp_dir = tempdir ( ) . unwrap ( ) ;
146
147
let db_path = temp_dir. path ( ) . join ( "test.db" ) ;
148
+ gen_metadata_file ( & db_path, 3278479626 , 0 , 0 , 1 ) ;
147
149
148
150
// Create initial sync context and push a frame
149
151
let sync_ctx = SyncContext :: new (
@@ -211,6 +213,7 @@ async fn test_sync_context_retry_on_error() {
211
213
let server = MockServer :: start ( ) ;
212
214
let temp_dir = tempdir ( ) . unwrap ( ) ;
213
215
let db_path = temp_dir. path ( ) . join ( "test.db" ) ;
216
+ gen_metadata_file ( & db_path, 3278479626 , 0 , 0 , 1 ) ;
214
217
215
218
let sync_ctx = SyncContext :: new (
216
219
server. connector ( ) ,
@@ -475,3 +478,15 @@ impl hyper::client::connect::Connection for MockConnection {
475
478
hyper:: client:: connect:: Connected :: new ( )
476
479
}
477
480
}
481
+
482
+ fn gen_metadata_file ( db_path : & Path , hash : u32 , version : u32 , durable_frame_num : u32 , generation : u32 ) {
483
+ let metadata_path = format ! ( "{}-info" , db_path. to_str( ) . unwrap( ) ) ;
484
+ std:: fs:: write (
485
+ & metadata_path,
486
+ format ! (
487
+ "{{\" hash\" : {hash}, \" version\" : {version}, \" durable_frame_num\" : {durable_frame_num}, \" generation\" : {generation}}}"
488
+ )
489
+ . as_bytes ( ) ,
490
+ )
491
+ . unwrap ( ) ;
492
+ }
0 commit comments