Skip to content

Commit

Permalink
closing the writer in the goroutine #178
Browse files Browse the repository at this point in the history
  • Loading branch information
Apoorva-GA committed May 29, 2018
1 parent 499b67d commit efcb675
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
6 changes: 3 additions & 3 deletions generator/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,6 @@ func GenerateReports(res *SuiteResult, reportsDir, themePath string) error {
if err != nil {
return err
}
defer sf.Close()
wg.Add(1)
go generateSpecPage(res, r, sf, &wg)
}
Expand Down Expand Up @@ -486,9 +485,10 @@ func generateIndexPages(suiteRes *SuiteResult, reportsDir string, wg *sync.WaitG
}
}

func generateSpecPage(suiteRes *SuiteResult, specRes *spec, w io.Writer, wg *sync.WaitGroup) {
func generateSpecPage(suiteRes *SuiteResult, specRes *spec, wc io.WriteCloser, wg *sync.WaitGroup) {
defer wc.Close()
defer wg.Done()
execTemplate("specPage", w, struct {
execTemplate("specPage", wc, struct {
SuiteRes *SuiteResult
SpecRes *spec
}{suiteRes, specRes})
Expand Down
18 changes: 17 additions & 1 deletion generator/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -799,14 +799,30 @@ var HTMLGenerationTests = []*HTMLGenerationTest{
{"spec error", suiteResWithSpecError, "spec_err.html"},
}

type myBuf struct {
buf *bytes.Buffer
}

func (b myBuf) Write(p []byte) (int, error) {
return b.buf.Write(p)
}

func (b myBuf) Close() error {
return nil
}

func (b myBuf) String() string {
return b.buf.String()
}

func TestHTMLGeneration(t *testing.T) {
for _, test := range HTMLGenerationTests {
content, err := ioutil.ReadFile(filepath.Join("_testdata", "integration", test.expectedFile))
if err != nil {
t.Errorf("Error reading expected HTML file: %s", err.Error())
}

buf := new(bytes.Buffer)
buf := myBuf{new(bytes.Buffer)}
var wg sync.WaitGroup
wg.Add(1)

Expand Down
3 changes: 3 additions & 0 deletions htmlReport.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ func createBatFileToExecuteHtmlReport(exPath, exTarget string) {
}

func createSymlinkToHtmlReport(exPath, exTarget string) {
if _, err := os.Lstat(exTarget); err == nil{
os.Remove(exTarget)
}
err := os.Symlink(exPath, exTarget)
if err != nil {
log.Printf("[Warning] Unable to create symlink %s\n", exTarget)
Expand Down

0 comments on commit efcb675

Please sign in to comment.