Commit 1236f0e2 authored by Aaron Jacobs's avatar Aaron Jacobs

Most of InterruptFSTest.InterruptedDuringRead.

parent 98fe7cbb
...@@ -15,12 +15,11 @@ ...@@ -15,12 +15,11 @@
package interruptfs_test package interruptfs_test
import ( import (
"bytes"
"os" "os"
"os/exec" "os/exec"
"path" "path"
"sync"
"testing" "testing"
"time"
"github.com/jacobsa/fuse/fuseutil" "github.com/jacobsa/fuse/fuseutil"
"github.com/jacobsa/fuse/samples" "github.com/jacobsa/fuse/samples"
...@@ -71,44 +70,27 @@ func (t *InterruptFSTest) StatFoo() { ...@@ -71,44 +70,27 @@ func (t *InterruptFSTest) StatFoo() {
} }
func (t *InterruptFSTest) InterruptedDuringRead() { func (t *InterruptFSTest) InterruptedDuringRead() {
// Start a sub-process that attempts to read the file. Wait for it in the var err error
// background.
// Start a sub-process that attempts to read the file.
cmd := exec.Command("cat", path.Join(t.Dir, "foo")) cmd := exec.Command("cat", path.Join(t.Dir, "foo"))
var cmdOutput []byte
var cmdErr error
var mu sync.Mutex var cmdOutput bytes.Buffer
cmdFinished := false cmd.Stdout = &cmdOutput
cmdFinishedChanged := sync.NewCond(&mu) cmd.Stderr = &cmdOutput
go func() { err = cmd.Start()
cmdOutput, cmdErr = cmd.CombinedOutput() AssertEq(nil, err)
mu.Lock()
cmdFinished = true
cmdFinishedChanged.Broadcast()
mu.Unlock()
}()
// Wait for the read to make it to the file system. // Wait for the read to make it to the file system.
t.fs.WaitForReadInFlight() t.fs.WaitForReadInFlight()
// Wait another moment. The command should still be hanging.
time.Sleep(100 * time.Millisecond)
func() {
mu.Lock()
defer mu.Unlock()
AssertFalse(cmdFinished)
}()
// Send SIGINT. // Send SIGINT.
cmd.Process.Signal(os.Interrupt) cmd.Process.Signal(os.Interrupt)
// Now the command should return, with an appropriate error. // The command should return, with an appropriate error.
mu.Lock() err = cmd.Wait()
for !cmdFinished {
cmdFinishedChanged.Wait()
}
mu.Unlock()
AssertTrue(false, "TODO") AssertEq("TODO", err)
AssertEq("TODO", cmdOutput.String())
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment