fusefs: shorten and consolidate sleeps

Some fusefs tests must sleep because they deliberately trigger a race, or
because they're testing the cache timeout functionality.  Consolidate the
sleep interval in a single place so it will be easy to adjust.  Shorten it
from either 500ms or 250ms to 100ms.  From experiment I find that 10ms works
every time, so 100ms should be fairly safe.

Sponsored by:	The FreeBSD Foundation
This commit is contained in:
Alan Somers 2019-05-09 18:23:09 +00:00
parent f528b38f60
commit a87257ac25
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/projects/fuse2/; revision=347403
5 changed files with 21 additions and 33 deletions

View File

@ -100,11 +100,6 @@ TEST_F(Getattr, attr_cache_timeout)
const char RELPATH[] = "some_file.txt";
const uint64_t ino = 42;
struct stat sb;
/*
* The timeout should be longer than the longest plausible time the
* daemon would take to complete a write(2) to /dev/fuse, but no longer.
*/
long timeout_ns = 250'000'000;
expect_lookup(RELPATH, ino, S_IFREG | 0644, 0, 1, 0, 0);
EXPECT_CALL(*m_mock, process(
@ -116,14 +111,14 @@ TEST_F(Getattr, attr_cache_timeout)
).Times(2)
.WillRepeatedly(Invoke(ReturnImmediate([=](auto i __unused, auto out) {
SET_OUT_HEADER_LEN(out, attr);
out->body.attr.attr_valid_nsec = timeout_ns;
out->body.attr.attr_valid_nsec = NAP_NS / 2;
out->body.attr.attr_valid = 0;
out->body.attr.attr.ino = ino; // Must match nodeid
out->body.attr.attr.mode = S_IFREG | 0644;
})));
EXPECT_EQ(0, stat(FULLPATH, &sb));
usleep(2 * timeout_ns / 1000);
nap();
/* Timeout has expired. stat(2) should requery the daemon */
EXPECT_EQ(0, stat(FULLPATH, &sb));
}

View File

@ -69,7 +69,7 @@ void sigusr2_handler(int __unused sig) {
void* killer(void* target) {
/* Wait until the main thread is blocked in fdisp_wait_answ */
if (killer_should_sleep)
usleep(250'000);
nap();
else
sem_wait(blocked_semaphore);
if (verbosity > 1)
@ -478,7 +478,7 @@ TEST_F(Interrupt, in_kernel_restartable)
ASSERT_EQ(0, sem_post(&sem0)) << strerror(errno);
/* Wait awhile to make sure the signal generates no FUSE_INTERRUPT */
usleep(250'000);
nap();
pthread_join(th1, &thr1_value);
pthread_join(th0, &thr0_value);
@ -548,7 +548,7 @@ TEST_F(Interrupt, in_kernel_nonrestartable)
ASSERT_EQ(0, sem_post(&sem0)) << strerror(errno);
/* Wait awhile to make sure the signal generates no FUSE_INTERRUPT */
usleep(250'000);
nap();
pthread_join(th0, &thr0_value);
EXPECT_EQ(0, (intptr_t)thr0_value);
@ -700,7 +700,7 @@ TEST_F(Interrupt, priority)
ASSERT_EQ(0, mkdir(FULLDIRPATH1, MODE)) << strerror(errno);
/* Wait awhile to make sure the signal generates no FUSE_INTERRUPT */
usleep(250'000);
nap();
pthread_join(th0, NULL);
sem_destroy(&sem1);

View File

@ -110,18 +110,13 @@ TEST_F(Lookup, attr_cache_timeout)
const char RELPATH[] = "some_file.txt";
const uint64_t ino = 42;
struct stat sb;
/*
* The timeout should be longer than the longest plausible time the
* daemon would take to complete a write(2) to /dev/fuse, but no longer.
*/
long timeout_ns = 250'000'000;
EXPECT_LOOKUP(1, RELPATH)
.Times(2)
.WillRepeatedly(Invoke(ReturnImmediate([=](auto in __unused, auto out) {
SET_OUT_HEADER_LEN(out, entry);
out->body.entry.nodeid = ino;
out->body.entry.attr_valid_nsec = timeout_ns;
out->body.entry.attr_valid_nsec = NAP_NS / 2;
out->body.entry.attr.ino = ino; // Must match nodeid
out->body.entry.attr.mode = S_IFREG | 0644;
})));
@ -129,7 +124,7 @@ TEST_F(Lookup, attr_cache_timeout)
/* access(2) will issue a VOP_LOOKUP and fill the attr cache */
ASSERT_EQ(0, access(FULLPATH, F_OK)) << strerror(errno);
/* Next access(2) will use the cached attributes */
usleep(2 * timeout_ns / 1000);
nap();
/* The cache has timed out; VOP_GETATTR should query the daemon*/
ASSERT_EQ(0, stat(FULLPATH, &sb)) << strerror(errno);
}
@ -247,11 +242,7 @@ TEST_F(Lookup, entry_cache_negative_timeout)
{
const char *RELPATH = "does_not_exist";
const char *FULLPATH = "mountpoint/does_not_exist";
/*
* The timeout should be longer than the longest plausible time the
* daemon would take to complete a write(2) to /dev/fuse, but no longer.
*/
struct timespec entry_valid = {.tv_sec = 0, .tv_nsec = 250'000'000};
struct timespec entry_valid = {.tv_sec = 0, .tv_nsec = NAP_NS / 2};
EXPECT_LOOKUP(1, RELPATH).Times(2)
.WillRepeatedly(Invoke(ReturnNegativeCache(&entry_valid)));
@ -259,7 +250,7 @@ TEST_F(Lookup, entry_cache_negative_timeout)
EXPECT_NE(0, access(FULLPATH, F_OK));
EXPECT_EQ(ENOENT, errno);
usleep(2 * entry_valid.tv_nsec / 1000);
nap();
/* The cache has timed out; VOP_LOOKUP should requery the daemon*/
EXPECT_NE(0, access(FULLPATH, F_OK));
@ -274,17 +265,12 @@ TEST_F(Lookup, entry_cache_timeout)
{
const char FULLPATH[] = "mountpoint/some_file.txt";
const char RELPATH[] = "some_file.txt";
/*
* The timeout should be longer than the longest plausible time the
* daemon would take to complete a write(2) to /dev/fuse, but no longer.
*/
long timeout_ns = 250'000'000;
EXPECT_LOOKUP(1, RELPATH)
.Times(2)
.WillRepeatedly(Invoke(ReturnImmediate([=](auto in __unused, auto out) {
SET_OUT_HEADER_LEN(out, entry);
out->body.entry.entry_valid_nsec = timeout_ns;
out->body.entry.entry_valid_nsec = NAP_NS / 2;
out->body.entry.attr.mode = S_IFREG | 0644;
out->body.entry.nodeid = 14;
})));
@ -293,7 +279,7 @@ TEST_F(Lookup, entry_cache_timeout)
ASSERT_EQ(0, access(FULLPATH, F_OK)) << strerror(errno);
/* Next access(2) will use the cached entry */
ASSERT_EQ(0, access(FULLPATH, F_OK)) << strerror(errno);
usleep(2 * timeout_ns / 1000);
nap();
/* The cache has timed out; VOP_LOOKUP should requery the daemon*/
ASSERT_EQ(0, access(FULLPATH, F_OK)) << strerror(errno);
}

View File

@ -200,7 +200,7 @@ TEST_F(AioRead, async_read_disabled)
* Sleep for awhile to make sure the kernel has had a chance to issue
* the second read, even though the first has not yet returned
*/
usleep(250'000);
nap();
/* Deliberately leak iocbs */
/* Deliberately leak fd. close(2) will be tested in release.cc */
@ -278,7 +278,7 @@ TEST_F(AsyncRead, DISABLED_async_read)
* Sleep for awhile to make sure the kernel has had a chance to issue
* both reads.
*/
usleep(250'000);
nap();
/* Deliberately leak iocbs */
/* Deliberately leak fd. close(2) will be tested in release.cc */

View File

@ -37,7 +37,14 @@
#define FUSE_WRITE_CACHE 1
#endif
/* Nanoseconds to sleep, for tests that must */
#define NAP_NS (100'000'000)
void get_unprivileged_id(uid_t *uid, gid_t *gid);
inline void nap()
{
usleep(NAP_NS / 1000);
}
class FuseTest : public ::testing::Test {
protected: