diff options
author | Oleksandr Byelkin <sanja@mariadb.com> | 2019-02-21 14:40:52 +0100 |
---|---|---|
committer | Oleksandr Byelkin <sanja@mariadb.com> | 2019-02-21 14:40:52 +0100 |
commit | 93ac7ae70ff000353538f732899b421a3f2ea7ce (patch) | |
tree | 819b5ca057d80b42699de219c982b7924857c406 /unittest | |
parent | 4932aba921755cfbc351b92c67068a5c48d3922b (diff) | |
parent | a40de1bdeb218d66d5cc737758a4bab1b06f255d (diff) | |
download | mariadb-git-93ac7ae70ff000353538f732899b421a3f2ea7ce.tar.gz |
Merge branch '10.3' into 10.4
Diffstat (limited to 'unittest')
-rw-r--r-- | unittest/mysys/thr_template.c | 4 | ||||
-rw-r--r-- | unittest/sql/mf_iocache-t.cc | 70 |
2 files changed, 71 insertions, 3 deletions
diff --git a/unittest/mysys/thr_template.c b/unittest/mysys/thr_template.c index 3a57ed091e9..3606a253ae4 100644 --- a/unittest/mysys/thr_template.c +++ b/unittest/mysys/thr_template.c @@ -34,7 +34,7 @@ void test_concurrently(const char *test, pthread_handler handler, int n, int m) bad= 0; diag("Testing %s with %d threads, %d iterations... ", test, n, m); - for (i= n; i; i--) + for (i= 0; i < n; i++) { if (pthread_create(&threads[i], 0, handler, &m) != 0) { @@ -43,7 +43,7 @@ void test_concurrently(const char *test, pthread_handler handler, int n, int m) } } - for (i= n; i; i--) + for (i= 0; i < n; i++) pthread_join(threads[i], 0); now= my_interval_timer() - now; diff --git a/unittest/sql/mf_iocache-t.cc b/unittest/sql/mf_iocache-t.cc index 8397c539dd5..27c4b8d0e2a 100644 --- a/unittest/sql/mf_iocache-t.cc +++ b/unittest/sql/mf_iocache-t.cc @@ -372,10 +372,77 @@ void mdev17133() } +void mdev10963() +{ + int res; + uint n_checks= 8; + uchar buf[1024 * 512]; + uint n_frag= sizeof(buf)/(2 * CACHE_SIZE); + FILE *file; + myf my_flags= MYF(MY_WME); + const char *file_name="cache.log"; + + memset(buf, FILL, sizeof(buf)); + diag("MDEV-10963 Fragmented BINLOG query"); + + init_io_cache_encryption(); + srand((uint) time(NULL)); + + /* copying source */ + res= open_cached_file(&info, 0, 0, CACHE_SIZE, 0); + ok(res == 0, "open_cached_file" INFO_TAIL); + res= my_b_write(&info, buf, sizeof(buf)); + + ulonglong total_size= my_b_tell(&info); + ok(res == 0 && total_size == sizeof(buf), "cache is written"); + + /* destination */ + file= my_fopen(file_name, O_RDWR | O_TRUNC | O_CREAT, my_flags); + ok(my_fileno(file) > 0, "opened file fd = %d", my_fileno(file)); + + /* + For n_checks times verify a sequence of copying with random fragment + size ranging from zero to about the double of the cache read buffer size. + */ + for (; n_checks; n_checks--, rewind(file)) + { + // copied size is an estimate can be incremeneted to greater than total_size + ulong copied_size= 0; + + res= reinit_io_cache(&info, READ_CACHE, 0L, FALSE, FALSE); + ok(res == 0, "cache turned to read"); + + for (ulong i= 0, curr_size= 0; i < n_frag; i++, copied_size += curr_size) + { + curr_size= rand() % (2 * (total_size - copied_size) / (n_frag - i)); + + DBUG_ASSERT(curr_size <= total_size - copied_size || i == n_frag - 1); + + res= my_b_copy_to_file(&info, file, curr_size); + ok(res == 0, "%lu of the cache copied to file", curr_size); + } + /* + Regardless of total_size <> copied_size the function succeeds: + when total_size < copied_size the huge overflowed value of the last + argument is ignored because nothing already left uncopied in the cache. + */ + res= my_b_copy_to_file(&info, file, (size_t) total_size - copied_size); + ok(res == 0, "%llu of the cache copied to file", total_size - copied_size); + ok(my_ftell(file, my_flags) == sizeof(buf), + "file written in %d fragments", n_frag+1); + + res= reinit_io_cache(&info, WRITE_CACHE, total_size, 0, 0); + ok(res == 0 && my_b_tell(&info) == sizeof(buf), "cache turned to write"); + } + close_cached_file(&info); + my_fclose(file, my_flags); + my_delete(file_name, MYF(MY_WME)); +} + int main(int argc __attribute__((unused)),char *argv[]) { MY_INIT(argv[0]); - plan(114); + plan(277); /* temp files with and without encryption */ encrypt_tmp_files= 1; @@ -393,6 +460,7 @@ int main(int argc __attribute__((unused)),char *argv[]) mdev14014(); mdev17133(); + mdev10963(); my_end(0); return exit_status(); |