From c72538b734fe866046ba4756d0a040386ae60a56 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 8 Sep 2014 13:45:52 -0700 Subject: [PATCH] ceph_test_rados_api_io: add read timeout test Verify we don't receive data after a timeout. Based on reproducer for #9362 written by Matthias Kiefer . Signed-off-by: Sage Weil --- src/test/librados/io.cc | 52 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/test/librados/io.cc b/src/test/librados/io.cc index ede81a326f5bc..0cfa91e4b8468 100644 --- a/src/test/librados/io.cc +++ b/src/test/librados/io.cc @@ -25,6 +25,58 @@ TEST_F(LibRadosIo, SimpleWrite) { ASSERT_EQ(0, rados_write(ioctx, "foo", buf, sizeof(buf), 0)); } +TEST_F(LibRadosIo, ReadTimeout) { + char buf[128]; + memset(buf, 'a', sizeof(buf)); + ASSERT_EQ(0, rados_write(ioctx, "foo", buf, sizeof(buf), 0)); + + { + // set up a second client + rados_t cluster; + rados_ioctx_t ioctx; + rados_create(&cluster, "admin"); + rados_conf_read_file(cluster, NULL); + rados_conf_parse_env(cluster, NULL); + rados_conf_set(cluster, "rados_osd_op_timeout", "0.00001"); // use any small value that will result in a timeout + rados_connect(cluster); + rados_ioctx_create(cluster, pool_name.c_str(), &ioctx); + rados_ioctx_set_namespace(ioctx, nspace.c_str()); + + // then we show that the buffer is changed after rados_read returned + // with a timeout + for (int i=0; i<5; i++) { + char buf2[sizeof(buf)]; + memset(buf2, 0, sizeof(buf2)); + int err = rados_read(ioctx, "foo", buf2, sizeof(buf2), 0); + if (err == -110) { + int startIndex = 0; + // find the index until which librados already read the object before the timeout occurred + for (unsigned b=0; b