mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-02-09 13:47:11 +02:00
fall back to slower speed if test fails
This commit is contained in:
parent
08f8472db3
commit
dc953ea680
@ -106,36 +106,48 @@ func Test(t *testing.T) {
|
||||
for _, test := range tests {
|
||||
test := test
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
testPath := filepath.Join(rootDir, "test", "integration", test.name)
|
||||
findOrCreateDir(testPath)
|
||||
speeds := []int{10, 5, 1}
|
||||
for i, speed := range speeds {
|
||||
fmt.Printf("%s: trying again at speed %d\n", test.name, speed)
|
||||
|
||||
snapshotPath := filepath.Join(testPath, "snapshot.txt")
|
||||
testPath := filepath.Join(rootDir, "test", "integration", test.name)
|
||||
findOrCreateDir(testPath)
|
||||
|
||||
err := os.Chdir(rootDir)
|
||||
assert.NoError(t, err)
|
||||
snapshotPath := filepath.Join(testPath, "snapshot.txt")
|
||||
|
||||
prepareIntegrationTestDir()
|
||||
|
||||
err = createFixture(rootDir, test.fixture)
|
||||
assert.NoError(t, err)
|
||||
|
||||
record := os.Getenv("RECORD_EVENTS") != ""
|
||||
runLazygit(t, testPath, rootDir, record)
|
||||
|
||||
updateSnapshot := record || os.Getenv("UPDATE_SNAPSHOT") != ""
|
||||
|
||||
actual := generateSnapshot(t)
|
||||
|
||||
if updateSnapshot {
|
||||
err := ioutil.WriteFile(snapshotPath, []byte(actual), 0600)
|
||||
err := os.Chdir(rootDir)
|
||||
assert.NoError(t, err)
|
||||
|
||||
prepareIntegrationTestDir()
|
||||
|
||||
err = createFixture(rootDir, test.fixture)
|
||||
assert.NoError(t, err)
|
||||
|
||||
record := os.Getenv("RECORD_EVENTS") != ""
|
||||
runLazygit(t, testPath, rootDir, record, speed)
|
||||
|
||||
updateSnapshot := record || os.Getenv("UPDATE_SNAPSHOT") != ""
|
||||
|
||||
actual := generateSnapshot(t)
|
||||
|
||||
if updateSnapshot {
|
||||
err := ioutil.WriteFile(snapshotPath, []byte(actual), 0600)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
expectedBytes, err := ioutil.ReadFile(snapshotPath)
|
||||
assert.NoError(t, err)
|
||||
expected := string(expectedBytes)
|
||||
|
||||
if expected == actual {
|
||||
break
|
||||
}
|
||||
|
||||
// if the snapshots and we haven't tried all playback speeds different we'll retry at a slower speed
|
||||
if i == len(speeds)-1 {
|
||||
assert.Equal(t, expected, actual, fmt.Sprintf("expected:\n%s\nactual:\n%s\n", expected, actual))
|
||||
}
|
||||
}
|
||||
|
||||
expectedBytes, err := ioutil.ReadFile(snapshotPath)
|
||||
assert.NoError(t, err)
|
||||
expected := string(expectedBytes)
|
||||
|
||||
assert.Equal(t, expected, actual, fmt.Sprintf("expected:\n%s\nactual:\n%s\n", expected, actual))
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -169,7 +181,7 @@ func gotoRootDirectory() {
|
||||
}
|
||||
}
|
||||
|
||||
func runLazygit(t *testing.T, testPath string, rootDir string, record bool) {
|
||||
func runLazygit(t *testing.T, testPath string, rootDir string, record bool, speed int) {
|
||||
osCommand := oscommands.NewDummyOSCommand()
|
||||
|
||||
replayPath := filepath.Join(testPath, "recording.json")
|
||||
@ -193,6 +205,8 @@ func runLazygit(t *testing.T, testPath string, rootDir string, record bool) {
|
||||
cmdStr = fmt.Sprintf("%s --use-config-dir=%s", cmdStr, configDir)
|
||||
|
||||
cmd := osCommand.ExecutableFromString(cmdStr)
|
||||
cmd.Env = append(cmd.Env, fmt.Sprintf("REPLAY_SPEED=%d", speed))
|
||||
|
||||
if record {
|
||||
cmd.Env = append(
|
||||
cmd.Env,
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/jesseduffield/gocui"
|
||||
@ -38,14 +39,22 @@ func (gui *Gui) replayRecordedEvents() {
|
||||
// might need to add leeway if this ends up flakey
|
||||
var leeway int64 = 0
|
||||
// humans are slow so this speeds things up.
|
||||
var speed int64 = 5
|
||||
speed := 1
|
||||
envReplaySpeed := os.Getenv("REPLAY_SPEED")
|
||||
if envReplaySpeed != "" {
|
||||
var err error
|
||||
speed, err = strconv.Atoi(envReplaySpeed)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
for _, event := range events {
|
||||
middle:
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
now := gui.timeSinceStart()*speed - leeway
|
||||
now := gui.timeSinceStart()*int64(speed) - leeway
|
||||
if gui.g != nil && now >= event.Timestamp {
|
||||
gui.g.ReplayedEvents <- *event.Event
|
||||
break middle
|
||||
|
Loading…
x
Reference in New Issue
Block a user