Skip to content

Commit

Permalink
change build delay to zero (#343)
Browse files Browse the repository at this point in the history
* change build delay to zero

Co-authored-by: xiantang <zhujingdi1998@gamil.com>
  • Loading branch information
xiantang and xiantang authored Oct 24, 2022
1 parent 3be9ef7 commit a2b8871
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 26 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ name: build

on:
push:
pull_request:
branches: [ master ]

jobs:
build:
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/smoke_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ name: smoke_test

on:
push:
pull_request:
branches: [ master ]

jobs:
smoke_test_ubuntu:
Expand Down
2 changes: 1 addition & 1 deletion air_example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ follow_symlink = true
# This log file places in your tmp_dir.
log = "air.log"
# It's not necessary to trigger build each time file changes if it's too frequent.
delay = 1000 # ms
delay = 0 # ms
# Stop running old binary when build errors occur.
stop_on_error = true
# Send Interrupt signal before killing process (windows does not support this feature)
Expand Down
5 changes: 2 additions & 3 deletions runner/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ type cfgScreen struct {
ClearOnRebuild bool `toml:"clear_on_rebuild"`
}

type sliceTransformer struct {
}
type sliceTransformer struct{}

func (t sliceTransformer) Transformer(typ reflect.Type) func(dst, src reflect.Value) error {
if typ.Kind() == reflect.Slice {
Expand Down Expand Up @@ -212,7 +211,7 @@ func defaultConfig() Config {
ExcludeDir: []string{"assets", "tmp", "vendor", "testdata"},
ArgsBin: []string{},
ExcludeRegex: []string{"_test.go"},
Delay: 1000,
Delay: 0,
}
if runtime.GOOS == PlatformWindows {
build.Bin = `tmp\main.exe`
Expand Down
28 changes: 10 additions & 18 deletions runner/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func TestRebuild(t *testing.T) {
// 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, 0644)
file, err := os.OpenFile("main.go", os.O_APPEND|os.O_WRONLY, 0o644)
if err != nil {
t.Fatalf("Should not be fail: %s.", err)
}
Expand Down Expand Up @@ -349,7 +349,6 @@ func TestFixCloseOfChannelAfterCtrlC(t *testing.T) {
t.Fatalf("Should not be fail: %s.", err)
}
assert.False(t, engine.running)

}

func TestFixCloseOfChannelAfterTwoFailedBuild(t *testing.T) {
Expand Down Expand Up @@ -382,7 +381,7 @@ func TestFixCloseOfChannelAfterTwoFailedBuild(t *testing.T) {
time.Sleep(time.Second * 3)

// edit *.go file to create build error again
file, err := os.OpenFile("main.go", os.O_APPEND|os.O_WRONLY, 0644)
file, err := os.OpenFile("main.go", os.O_APPEND|os.O_WRONLY, 0o644)
if err != nil {
t.Fatalf("Should not be fail: %s.", err)
}
Expand Down Expand Up @@ -525,7 +524,6 @@ go 1.17

// generateGoCode generates golang code to tempdir
func generateGoCode(dir string, port int) error {

code := fmt.Sprintf(`package main
import (
Expand Down Expand Up @@ -590,7 +588,7 @@ func TestRebuildWhenRunCmdUsingDLV(t *testing.T) {
// just append a new empty line to main.go
time.Sleep(time.Second * 2)
go func() {
file, err := os.OpenFile("main.go", os.O_APPEND|os.O_WRONLY, 0644)
file, err := os.OpenFile("main.go", os.O_APPEND|os.O_WRONLY, 0o644)
if err != nil {
t.Fatalf("Should not be fail: %s.", err)
}
Expand Down Expand Up @@ -668,7 +666,7 @@ exclude_file = ["main.go"]
include_file = ["test/not_a_test.go"]
`
if err := ioutil.WriteFile(dftTOML, []byte(config), 0644); err != nil {
if err := ioutil.WriteFile(dftTOML, []byte(config), 0o644); err != nil {
t.Fatal(err)
}
engine, err := NewEngine(".air.toml", true)
Expand All @@ -682,7 +680,6 @@ include_file = ["test/not_a_test.go"]
assert.Equal(t, []string{"main.go"}, engine.config.Build.ExcludeFile)
assert.Equal(t, []string{"test/not_a_test.go"}, engine.config.Build.IncludeFile)
assert.Equal(t, "go build .", engine.config.Build.Cmd)

}

func TestShouldIncludeGoTestFile(t *testing.T) {
Expand Down Expand Up @@ -728,7 +725,7 @@ func Test(t *testing.T) {
t.Fatal(err)
}

time.Sleep(time.Second * 3)
time.Sleep(time.Second * 2)
engine, err := NewEngine(".air.toml", false)
if err != nil {
t.Fatal(err)
Expand All @@ -744,18 +741,14 @@ func Test(t *testing.T) {
t.Fatal(err)
}
go func() {
file, err := os.OpenFile("main_test.go", os.O_APPEND|os.O_WRONLY, 0644)
if err != nil {
t.Fatalf("Should not be fail: %s.", err)
}
file, err = os.OpenFile("main_test.go", os.O_APPEND|os.O_WRONLY, 0o644)
assert.NoError(t, err)
defer file.Close()
_, err = file.WriteString("\n")
if err != nil {
t.Fatalf("Should not be fail: %s.", err)
}
assert.NoError(t, err)
}()
// should Have rebuild
if err = waitingPortConnectionRefused(t, port, time.Second*10); err != nil {
if err = waitingPortReady(t, port, time.Second*10); err != nil {
t.Fatal(err)
}
}
Expand Down Expand Up @@ -784,7 +777,7 @@ func TestCreateNewDir(t *testing.T) {
assert.True(t, checkPortHaveBeenUsed(port))

// create a new dir make dir
if err = os.Mkdir(tmpDir+"/dir", 0644); err != nil {
if err = os.Mkdir(tmpDir+"/dir", 0o644); err != nil {
t.Fatal(err)
}

Expand All @@ -794,7 +787,6 @@ func TestCreateNewDir(t *testing.T) {
}
engine.Stop()
time.Sleep(2 * time.Second)

}

func TestShouldIncludeIncludedFile(t *testing.T) {
Expand Down

0 comments on commit a2b8871

Please sign in to comment.