Skip to content

Commit

Permalink
Merge pull request #202 from buger/file-input-speed-fix
Browse files Browse the repository at this point in the history
Fix file input replay speed
  • Loading branch information
buger committed Sep 3, 2015
2 parents d81e39d + 6d2a895 commit 766bbc6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ drun:
docker run -v `pwd`:$(SOURCE_PATH) -t -i gor go run $(SOURCE) --input-dummy=0 --output-http="http://localhost:9000" --input-raw :9000 --input-http :9000 --verbose --debug --middleware "./examples/middleware/echo.sh"

drun-2:
docker run -v `pwd`:$(SOURCE_PATH) -t -i gor go run $(SOURCE) --input-http :9001 --output-dummy=0
docker run -v `pwd`:$(SOURCE_PATH) -t -i gor go run $(SOURCE) --input-file ./fixtures/requests.gor --output-dummy=0

drecord:
docker run -v `pwd`:$(SOURCE_PATH) -t -i gor go run $(SOURCE) --input-dummy=0 --output-file=requests.gor --verbose --debug
Expand Down
15 changes: 9 additions & 6 deletions input_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,18 @@ func (i *FileInput) emit() {
buf := scanner.Bytes()
meta := payloadMeta(buf)

if meta[0][0] == RequestPayload && lastTime != 0 {
if meta[0][0] == RequestPayload {
ts, _ := strconv.ParseInt(string(meta[2]), 10, 64)
timeDiff := ts - lastTime

if i.speedFactor != 1 {
timeDiff = int64(float64(timeDiff) / i.speedFactor)
}
if lastTime != 0 {
timeDiff := ts - lastTime

if i.speedFactor != 1 {
timeDiff = int64(float64(timeDiff) / i.speedFactor)
}

time.Sleep(time.Duration(timeDiff))
time.Sleep(time.Duration(timeDiff))
}

lastTime = ts
}
Expand Down

0 comments on commit 766bbc6

Please sign in to comment.