Added a random delays feature for #8.
parent
6305cb930b
commit
02d14a685e
|
@ -15,12 +15,19 @@
|
||||||
package fuseutil
|
package fuseutil
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
"io"
|
"io"
|
||||||
|
"math/rand"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/jacobsa/fuse"
|
"github.com/jacobsa/fuse"
|
||||||
"github.com/jacobsa/fuse/fuseops"
|
"github.com/jacobsa/fuse/fuseops"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var fRandDelays = flag.Bool(
|
||||||
|
"fuseutil.rand_delays", false,
|
||||||
|
"If set, randomly delay each op received, to help expose concurrency issues.")
|
||||||
|
|
||||||
// An interface with a method for each op type in the fuseops package. This can
|
// An interface with a method for each op type in the fuseops package. This can
|
||||||
// be used in conjunction with NewFileSystemServer to avoid writing a "dispatch
|
// be used in conjunction with NewFileSystemServer to avoid writing a "dispatch
|
||||||
// loop" that switches on op types, instead receiving typed method calls
|
// loop" that switches on op types, instead receiving typed method calls
|
||||||
|
@ -109,6 +116,14 @@ func (s fileSystemServer) ServeOps(c *fuse.Connection) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s fileSystemServer) handleOp(op fuseops.Op) {
|
func (s fileSystemServer) handleOp(op fuseops.Op) {
|
||||||
|
// Delay if requested.
|
||||||
|
if *fRandDelays {
|
||||||
|
const delayLimit = 100 * time.Microsecond
|
||||||
|
delay := time.Duration(rand.Int63n(int64(delayLimit)))
|
||||||
|
time.Sleep(delay)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dispatch to the appropriate method.
|
||||||
switch typed := op.(type) {
|
switch typed := op.(type) {
|
||||||
default:
|
default:
|
||||||
op.Respond(fuse.ENOSYS)
|
op.Respond(fuse.ENOSYS)
|
||||||
|
|
Loading…
Reference in New Issue