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

Most of InterruptFSTest.InterruptedDuringRead.

parent 98fe7cbb
......@@ -15,12 +15,11 @@
package interruptfs_test
import (
"bytes"
"os"
"os/exec"
"path"
"sync"
"testing"
"time"
"github.com/jacobsa/fuse/fuseutil"
"github.com/jacobsa/fuse/samples"
......@@ -71,44 +70,27 @@ func (t *InterruptFSTest) StatFoo() {
}
func (t *InterruptFSTest) InterruptedDuringRead() {
// Start a sub-process that attempts to read the file. Wait for it in the
// background.
var err error
// Start a sub-process that attempts to read the file.
cmd := exec.Command("cat", path.Join(t.Dir, "foo"))
var cmdOutput []byte
var cmdErr error
var mu sync.Mutex
cmdFinished := false
cmdFinishedChanged := sync.NewCond(&mu)
var cmdOutput bytes.Buffer
cmd.Stdout = &cmdOutput
cmd.Stderr = &cmdOutput
go func() {
cmdOutput, cmdErr = cmd.CombinedOutput()
mu.Lock()
cmdFinished = true
cmdFinishedChanged.Broadcast()
mu.Unlock()
}()
err = cmd.Start()
AssertEq(nil, err)
// Wait for the read to make it to the file system.
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.
cmd.Process.Signal(os.Interrupt)
// Now the command should return, with an appropriate error.
mu.Lock()
for !cmdFinished {
cmdFinishedChanged.Wait()
}
mu.Unlock()
// The command should return, with an appropriate error.
err = cmd.Wait()
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