Skip to content

Commit

Permalink
fix #583 panic on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
xiantang committed Jun 23, 2024
1 parent 6697b69 commit 0febf6b
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 77 deletions.
3 changes: 0 additions & 3 deletions runner/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"path/filepath"
"strings"
"sync"
"sync/atomic"
"time"

"github.com/gohugoio/hugo/watcher/filenotify"
Expand All @@ -34,7 +33,6 @@ type Engine struct {

mu sync.RWMutex
watchers uint
round uint64
fileChecksums *checksumMap

ll sync.Mutex // lock for logger
Expand Down Expand Up @@ -547,7 +545,6 @@ func (e *Engine) runBin() error {
}

wg.Add(1)
atomic.AddUint64(&e.round, 1)
e.withLock(func() {
close(e.binStopCh)
e.binStopCh = make(chan bool)
Expand Down
74 changes: 0 additions & 74 deletions runner/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"runtime"
"strings"
"sync"
"sync/atomic"
"syscall"
"testing"
"time"
Expand Down Expand Up @@ -112,79 +111,6 @@ func TestRegexes(t *testing.T) {
}
}

func TestRerun(t *testing.T) {
tmpDir := initWithQuickExitGoCode(t)
// change dir to tmpDir
chdir(t, tmpDir)
engine, err := NewEngine("", true)
engine.config.Build.ExcludeUnchanged = true
engine.config.Build.Rerun = true
engine.config.Build.RerunDelay = 100
if err != nil {
t.Fatalf("Should not be fail: %s.", err)
}
go func() {
engine.Run()
t.Logf("engine run")
}()

time.Sleep(time.Second * 1)

// stop engine
engine.Stop()
time.Sleep(time.Second * 1)
t.Logf("engine stopped")

if atomic.LoadUint64(&engine.round) <= 1 {
t.Fatalf("The engine did't rerun")
}
}

func TestRerunWhenFileChanged(t *testing.T) {
tmpDir := initWithQuickExitGoCode(t)
// change dir to tmpDir
chdir(t, tmpDir)
engine, err := NewEngine("", true)
engine.config.Build.ExcludeUnchanged = true
engine.config.Build.Rerun = true
engine.config.Build.RerunDelay = 100
if err != nil {
t.Fatalf("Should not be fail: %s.", err)
}
go func() {
engine.Run()
t.Logf("engine run")
}()
time.Sleep(time.Second * 1)

roundBeforeChange := atomic.LoadUint64(&engine.round)

t.Logf("start change main.go")
// change file of main.go
// just append a new empty line to main.go
time.Sleep(time.Second * 2)
file, err := os.OpenFile("main.go", os.O_APPEND|os.O_WRONLY, 0o644)
if err != nil {
t.Fatalf("Should not be fail: %s.", err)
}
defer file.Close()
_, err = file.WriteString("\n")
if err != nil {
t.Fatalf("Should not be fail: %s.", err)
}

time.Sleep(time.Second * 1)
// stop engine
engine.Stop()
time.Sleep(time.Second * 1)
t.Logf("engine stopped")

roundAfterChange := atomic.LoadUint64(&engine.round)
if roundBeforeChange+1 >= roundAfterChange {
t.Fatalf("The engine didn't rerun")
}
}

func TestRunCommand(t *testing.T) {
// generate a random port
port, f := GetPort()
Expand Down

0 comments on commit 0febf6b

Please sign in to comment.