git: 86885b186898 - main - Fix intermittency in the sys.fs.fusefs.mknod.main test

From: Alan Somers <asomers_at_FreeBSD.org>
Date: Fri, 06 Oct 2023 19:57:48 UTC
The branch main has been updated by asomers:

URL: https://cgit.FreeBSD.org/src/commit/?id=86885b18689889e9b9142fd31d8c67f21334ba32

commit 86885b18689889e9b9142fd31d8c67f21334ba32
Author:     Alan Somers <asomers@FreeBSD.org>
AuthorDate: 2023-10-06 19:46:42 +0000
Commit:     Alan Somers <asomers@FreeBSD.org>
CommitDate: 2023-10-06 19:57:38 +0000

    Fix intermittency in the sys.fs.fusefs.mknod.main test
    
    In the Mknod.parent_inode test case, the kernel sends an extra
    FUSE_FORGET message.  But because it gets sent asynchronously with the
    failing syscall, it doesn't always get received before the test ends.
    So we never setup an expectation for it.  And 90+% of the time the test
    would exit successfully.
    
    Fix the intermittency by always waiting to receive the FUSE_FORGET
    message.
    
    MFC after:      2 weeks
    Sponsored by:   Axcient
---
 tests/sys/fs/fusefs/mknod.cc | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/tests/sys/fs/fusefs/mknod.cc b/tests/sys/fs/fusefs/mknod.cc
index 223d38f8acb1..1fb855f44f29 100644
--- a/tests/sys/fs/fusefs/mknod.cc
+++ b/tests/sys/fs/fusefs/mknod.cc
@@ -32,6 +32,7 @@ extern "C" {
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <sys/un.h>
+#include <semaphore.h>
 }
 
 #include "mockfs.hh"
@@ -255,14 +256,18 @@ TEST_F(Mknod, parent_inode)
 	const char RELPATH[] = "some_node";
 	mode_t mode = S_IFSOCK | 0755;
 	struct sockaddr_un sa;
+	sem_t sem;
 	int fd;
 	dev_t rdev = -1;	/* Really it's a don't care */
 	uint64_t ino = 42;
 
+	ASSERT_EQ(0, sem_init(&sem, 0, 0)) << strerror(errno);
+
 	expect_lookup(PPATH, ino, S_IFDIR | 0755, 0, 1);
 	EXPECT_LOOKUP(ino, RELPATH)
 	.WillOnce(Invoke(ReturnErrno(ENOENT)));
 	expect_mknod(ino, RELPATH, ino, mode, rdev);
+	expect_forget(ino, 1, &sem);
 
 	fd = socket(AF_UNIX, SOCK_STREAM, 0);
 	ASSERT_LE(0, fd) << strerror(errno);
@@ -273,6 +278,8 @@ TEST_F(Mknod, parent_inode)
 	ASSERT_EQ(EIO, errno);
 
 	leak(fd);
+	sem_wait(&sem);
+	sem_destroy(&sem);
 }
 
 /*