From: Christian Herdtweck Date: Thu, 14 Jan 2016 14:02:08 +0000 (+0100) Subject: created test that actually writes data to a filesystem to really test disc_fill_checked X-Git-Tag: v1.2~63 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=39af6ee0aa763a81c5bee9a32b1a3f83605a56f4;p=pyi2ncommon created test that actually writes data to a filesystem to really test disc_fill_checked --- diff --git a/test/disc_filler_test.py b/test/disc_filler_test.py new file mode 100755 index 0000000..0dca339 --- /dev/null +++ b/test/disc_filler_test.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python3 + +""" Test test_helpers.DiscFillChecker by actually writing lots of data to disc + +Indulge in the luxury of assuming we have python3 here ;-) + +.. codeauthor:: Christian Herdtweck, christian.herdtweck@intra2net.com +""" + +from sys import stderr, argv as cmd_line_args +from tempfile import NamedTemporaryFile +from time import monotonic +from os import fstatvfs + +from test_helpers import disc_fill_checked + +def main(test_dir): + """ Main function, called when running file as script """ + + with disc_fill_checked(): + fill_disc(test_dir) + + +def fill_disc(test_dir): + """ write data to file in given directory """ + + source = '/dev/random' + chunk_size = 1024 + temp_file_prefix = 'pyi2n_disc_fill_test_' + print_interval = 1 + + with open(source, 'rb') as read_handle: + with NamedTemporaryFile(dir=test_dir, prefix=temp_file_prefix) \ + as write_handle: + os_handle = write_handle.fileno() + print('copying data from {0} to {1}...'.format(source, + write_handle.name)) + print_fs_stats(os_handle) + last_print = monotonic() + while True: + write_handle.write(read_handle.read(chunk_size)) + if monotonic() - last_print > print_interval: + print_fs_stats(os_handle) + last_print = monotonic() + + +def print_fs_stats(os_handle): + print(fstatvfs(os_handle)) + + +if __name__ == '__main__': + if len(cmd_line_args) != 2: + print('Need to known which dir I am allowed to abuse', file=stderr) + exit(1) + main(cmd_line_args[1])