diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2017-12-17 02:12:19 +0000 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2018-02-01 16:45:54 -0800 |
commit | dbe3d3e91d6dbcf4d53aa8430d86f82b3a7937a8 (patch) | |
tree | b72c6b7fe20f49902fbf49e31620118f5bcf423e | |
parent | b61846f2dfdf84f8c3a1a6985060c45bdff0ad53 (diff) | |
download | libgit2-dbe3d3e91d6dbcf4d53aa8430d86f82b3a7937a8.tar.gz |
odb_loose: test reading a large file in stream
Since some test situations may have generous disk space, but limited RAM
(eg hosted build agents), test that we can stream a large file into a
loose object, and then stream it out of the loose object storage.
-rw-r--r-- | tests/odb/largefiles.c | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/tests/odb/largefiles.c b/tests/odb/largefiles.c index 22f136df5..5a1ec5e2b 100644 --- a/tests/odb/largefiles.c +++ b/tests/odb/largefiles.c @@ -1,5 +1,9 @@ #include "clar_libgit2.h" #include "git2/odb_backend.h" +#include "hash.h" +#include "odb.h" + +#define LARGEFILE_SIZE 5368709122 static git_repository *repo; static git_odb *odb; @@ -25,7 +29,7 @@ static void writefile(git_oid *oid) for (i = 0; i < 3041; i++) cl_git_pass(git_buf_puts(&buf, "Hello, world.\n")); - cl_git_pass(git_odb_open_wstream(&stream, odb, 5368709122, GIT_OBJ_BLOB)); + cl_git_pass(git_odb_open_wstream(&stream, odb, LARGEFILE_SIZE, GIT_OBJ_BLOB)); for (i = 0; i < 126103; i++) cl_git_pass(git_odb_stream_write(stream, buf.ptr, buf.size)); @@ -73,6 +77,48 @@ void test_odb_largefiles__streamwrite(void) cl_assert_equal_oid(&expected, &oid); } +void test_odb_largefiles__streamread(void) +{ + git_oid oid, read_oid; + git_odb_stream *stream; + char buf[10240]; + char hdr[64]; + size_t len, total = 0; + git_hash_ctx hash; + git_otype type; + int hdr_len, ret; + + if (!cl_is_env_set("GITTEST_INVASIVE_FS_SIZE") || + !cl_is_env_set("GITTEST_SLOW")) + cl_skip(); + + writefile(&oid); + + cl_git_pass(git_odb_open_rstream(&stream, &len, &type, odb, &oid)); + + cl_assert_equal_sz(LARGEFILE_SIZE, len); + cl_assert_equal_i(GIT_OBJ_BLOB, type); + + cl_git_pass(git_hash_ctx_init(&hash)); + hdr_len = git_odb__format_object_header(hdr, sizeof(hdr), len, type); + + cl_git_pass(git_hash_update(&hash, hdr, hdr_len)); + + while ((ret = git_odb_stream_read(stream, buf, 10240)) > 0) { + cl_git_pass(git_hash_update(&hash, buf, ret)); + total += ret; + } + + cl_assert_equal_sz(LARGEFILE_SIZE, total); + + git_hash_final(&read_oid, &hash); + + cl_assert_equal_oid(&oid, &read_oid); + + git_hash_ctx_cleanup(&hash); + git_odb_stream_free(stream); +} + void test_odb_largefiles__read_into_memory(void) { git_oid oid; |