Skip to content

Commit

Permalink
修复report报告mac存在漏报问题 & version 1.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
zan8in committed May 5, 2022
1 parent 3eb95af commit e60ecbe
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 12 deletions.
3 changes: 2 additions & 1 deletion cmd/afrog/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ func main() {
r := result.(*core.Result)

lock.Lock()
defer lock.Unlock()

if !options.Silent {
options.CurrentCount++
Expand All @@ -77,6 +76,8 @@ func main() {
fmt.Printf("\r%d/%d | %d%% ", options.CurrentCount, options.Count, options.CurrentCount*100/options.Count)
}

lock.Unlock()

})
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion internal/runner/banner.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func ShowBanner() string {
return "afrog"
return "afrog 五一劳动节版"
}

func ShowUsage() string {
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type Ceye struct {
}

const afrogConfigFilename = "afrog-config.yaml"
const Version = "1.3.0"
const Version = "1.3.1"

// Create and initialize afrog-config.yaml configuration info
func New() (*Config, error) {
Expand Down
22 changes: 13 additions & 9 deletions pkg/html/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type HtmlTemplate struct {
Result *core.Result
Filename string
Number string
Syncfile *utils.Syncfile
}

const outputDirectory = "./reports"
Expand All @@ -30,14 +31,18 @@ func (ht *HtmlTemplate) New() error {
}

ouputFile := filepath.Join(outputDirectory, ht.Filename)
// if utils.Exists(ouputFile) {
// return errors.New("output filename had existed")
// }

os.MkdirAll(outputDirectory, os.ModePerm)
ht.Filename = ouputFile

return utils.WriteFile(ouputFile, []byte(header()))
os.Remove(ht.Filename)

sf, err := utils.NewSyncfile(ht.Filename)
if err != nil {
return err
}
ht.Syncfile = sf
sf.Write(header())
}
return nil
}
Expand Down Expand Up @@ -124,12 +129,11 @@ func (ht *HtmlTemplate) Html() string {
}

func (ht *HtmlTemplate) Append() {
r := ht.Html()
if len(r) > 0 {
utils.AppendString(ht.Filename, r)
// fmt.Println(err)
content := ht.Html()
if len(content) > 0 {
// utils.AppendString(ht.Filename, r)
ht.Syncfile.Write(content)
}
// fmt.Println(len(r))
}

func header() string {
Expand Down
32 changes: 32 additions & 0 deletions pkg/utils/syncfile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package utils

import (
"bufio"
"os"
"sync"
)

type Syncfile struct {
mutex *sync.Mutex
iohandler *os.File
}

func NewSyncfile(filename string) (*Syncfile, error) {
f, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
return nil, err
}
return &Syncfile{mutex: &sync.Mutex{}, iohandler: f}, nil
}

func (sf *Syncfile) Write(content string) {
sf.mutex.Lock()

wbuf := bufio.NewWriterSize(sf.iohandler, len(content))
wbuf.WriteString(content)
wbuf.Flush()

RandSleep(1)

sf.mutex.Unlock()
}

0 comments on commit e60ecbe

Please sign in to comment.