From 52741c2671169665bb4b4e15827161c6f6518676 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Sun, 27 Aug 2017 14:00:37 +1000 Subject: [PATCH] TestUnmountWedged: Don't deadlock if the Read fails --- fs/torrentfs_test.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/fs/torrentfs_test.go b/fs/torrentfs_test.go index 949951f6..19d5b1f1 100644 --- a/fs/torrentfs_test.go +++ b/fs/torrentfs_test.go @@ -1,6 +1,7 @@ package torrentfs import ( + "context" "fmt" "io/ioutil" "log" @@ -120,10 +121,18 @@ func TestUnmountWedged(t *testing.T) { if err := fuseConn.MountError; err != nil { t.Fatalf("mount error: %s", err) } + ctx, cancel := context.WithCancel(context.Background()) // Read the greeting file, though it will never be available. This should // "wedge" FUSE, requiring the fs object to be forcibly destroyed. The // read call will return with a FS error. go func() { + <-ctx.Done() + fs.mu.Lock() + fs.event.Broadcast() + fs.mu.Unlock() + }() + go func() { + defer cancel() _, err := ioutil.ReadFile(filepath.Join(layout.MountDir, tt.Info().Name)) if err == nil { t.Fatal("expected error reading greeting") @@ -132,7 +141,7 @@ func TestUnmountWedged(t *testing.T) { // Wait until the read has blocked inside the filesystem code. fs.mu.Lock() - for fs.blockedReads != 1 { + for fs.blockedReads != 1 && ctx.Err() == nil { fs.event.Wait() } fs.mu.Unlock()