Skip to content

Commit 6d2a895

Browse files
committed
Fix file input replay speed
1 parent d81e39d commit 6d2a895

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ drun:
4444
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"
4545

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

4949
drecord:
5050
docker run -v `pwd`:$(SOURCE_PATH) -t -i gor go run $(SOURCE) --input-dummy=0 --output-file=requests.gor --verbose --debug

input_file.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,18 @@ func (i *FileInput) emit() {
6161
buf := scanner.Bytes()
6262
meta := payloadMeta(buf)
6363

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

68-
if i.speedFactor != 1 {
69-
timeDiff = int64(float64(timeDiff) / i.speedFactor)
70-
}
67+
if lastTime != 0 {
68+
timeDiff := ts - lastTime
69+
70+
if i.speedFactor != 1 {
71+
timeDiff = int64(float64(timeDiff) / i.speedFactor)
72+
}
7173

72-
time.Sleep(time.Duration(timeDiff))
74+
time.Sleep(time.Duration(timeDiff))
75+
}
7376

7477
lastTime = ts
7578
}

0 commit comments

Comments
 (0)