Skip to content

Commit 81869a2

Browse files
Also test 'long' write
1 parent a3e5194 commit 81869a2

File tree

1 file changed

+37
-15
lines changed

1 file changed

+37
-15
lines changed

test-fixtures/src/bin/cache.rs

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -439,24 +439,46 @@ fn test_inconsistent_body_length() {
439439
assert!(fetch.is_none());
440440
}
441441

442-
let body = "hello beautiful world".as_bytes();
443-
let extra_len = body.len() + 10;
444-
let mut writer = insert(key.clone(), Duration::from_secs(10))
445-
.known_length(extra_len as u64)
446-
.execute()
447-
.unwrap();
442+
// Short write:
443+
{
444+
let body = "hello beautiful world".as_bytes();
445+
let extra_len = body.len() + 10;
446+
let mut writer = insert(key.clone(), Duration::from_secs(10))
447+
.known_length(extra_len as u64)
448+
.execute()
449+
.unwrap();
448450

449-
let found = lookup(key.clone()).execute().unwrap().unwrap();
450-
// In metadata, so should be immediately available:
451-
assert_eq!(found.known_length().unwrap(), extra_len as u64);
451+
let found = lookup(key.clone()).execute().unwrap().unwrap();
452+
// In metadata, so should be immediately available:
453+
assert_eq!(found.known_length().unwrap(), extra_len as u64);
452454

453-
// Finish writing, but it's a short write:
454-
writer.write_all(body).unwrap();
455-
writer.finish().unwrap();
455+
// Finish writing, but it's a short write:
456+
writer.write_all(body).unwrap();
457+
writer.finish().unwrap();
458+
459+
let mut got = found.to_stream().unwrap();
460+
let mut data = Vec::new();
461+
got.read_to_end(&mut data).unwrap_err();
462+
}
463+
464+
// Long write:
465+
{
466+
let body = "hello beautiful world".as_bytes();
467+
let extra_len = body.len() - 3;
468+
let mut writer = insert(key.clone(), Duration::from_secs(10))
469+
.known_length(extra_len as u64)
470+
.execute()
471+
.unwrap();
472+
473+
let found = lookup(key.clone()).execute().unwrap().unwrap();
474+
assert_eq!(found.known_length().unwrap(), extra_len as u64);
475+
writer.write_all(body).unwrap();
476+
writer.finish().unwrap();
456477

457-
let mut got = found.to_stream().unwrap();
458-
let mut data = Vec::new();
459-
got.read_to_end(&mut data).unwrap_err();
478+
let mut got = found.to_stream().unwrap();
479+
let mut data = Vec::new();
480+
got.read_to_end(&mut data).unwrap_err();
481+
}
460482
}
461483

462484
fn new_key() -> CacheKey {

0 commit comments

Comments
 (0)