Skip to content

Commit

Permalink
Remove time tracking (#278)
Browse files Browse the repository at this point in the history
  • Loading branch information
raviqqe authored Jan 29, 2023
1 parent 079b922 commit cf3cdaa
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 53 deletions.
6 changes: 2 additions & 4 deletions json_page_result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ func TestMarshalErrorJSONPageResult(t *testing.T) {
"http://foo.com",
[]*successLinkResult{},
[]*errorLinkResult{
{"http://foo.com/bar", errors.New("baz"), 0},
{"http://foo.com/bar", errors.New("baz")},
},
0,
}, false))
assert.Nil(t, err)
cupaloy.SnapshotT(t, bs)
Expand All @@ -28,10 +27,9 @@ func TestMarshalSuccessJSONPageResult(t *testing.T) {
&pageResult{
"http://foo.com",
[]*successLinkResult{
{"http://foo.com/foo", 200, 0},
{"http://foo.com/foo", 200},
},
[]*errorLinkResult{},
0,
}, true))
assert.Nil(t, err)
cupaloy.SnapshotT(t, bs)
Expand Down
17 changes: 5 additions & 12 deletions page_checker.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package main

import (
"sync"
"time"
)
import "sync"

type pageChecker struct {
fetcher *linkFetcher
Expand Down Expand Up @@ -43,10 +40,9 @@ func (c *pageChecker) checkPage(p *page) {
ec := make(chan *errorLinkResult, len(us))
w := sync.WaitGroup{}

pageStart := time.Now()
for u, err := range us {
if err != nil {
ec <- &errorLinkResult{u, err, time.Since(time.Now())}
ec <- &errorLinkResult{u, err}
continue
}

Expand All @@ -55,14 +51,12 @@ func (c *pageChecker) checkPage(p *page) {
go func(u string) {
defer w.Done()

linkStart := time.Now()
status, p, err := c.fetcher.Fetch(u)
linkElapsed := time.Since(linkStart)

if err == nil {
sc <- &successLinkResult{u, status, linkElapsed}
sc <- &successLinkResult{u, status}
} else {
ec <- &errorLinkResult{u, err, linkElapsed}
ec <- &errorLinkResult{u, err}
}

if !c.onePageOnly && p != nil && c.linkValidator.Validate(p.URL()) {
Expand All @@ -72,7 +66,6 @@ func (c *pageChecker) checkPage(p *page) {
}

w.Wait()
pageElapsed := time.Since(pageStart)

close(sc)
close(ec)
Expand All @@ -89,7 +82,7 @@ func (c *pageChecker) checkPage(p *page) {
es = append(es, e)
}

c.results <- &pageResult{p.URL().String(), ss, es, pageElapsed}
c.results <- &pageResult{p.URL().String(), ss, es}
}

func (c *pageChecker) addPage(p *page) {
Expand Down
9 changes: 2 additions & 7 deletions page_result.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
package main

import "time"

type pageResult struct {
URL string
SuccessLinkResults []*successLinkResult
ErrorLinkResults []*errorLinkResult
Elapsed time.Duration
}

type successLinkResult struct {
URL string
StatusCode int
Elapsed time.Duration
}

type errorLinkResult struct {
URL string
Error error
Elapsed time.Duration
URL string
Error error
}

func (r *pageResult) OK() bool {
Expand Down
28 changes: 11 additions & 17 deletions page_result_formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
func TestPageResultFormatterFormatEmptyResult(t *testing.T) {
cupaloy.SnapshotT(t,
newPageResultFormatter(false, true).Format(
&pageResult{"http://foo.com", nil, nil, 0},
&pageResult{"http://foo.com", nil, nil},
),
)
}
Expand All @@ -21,10 +21,9 @@ func TestPageResultFormatterFormatSuccessLinkResults(t *testing.T) {
&pageResult{
"http://foo.com",
[]*successLinkResult{
{"http://foo.com", 200, 0},
{"http://foo.com", 200},
},
nil,
0,
},
),
)
Expand All @@ -36,12 +35,11 @@ func TestPageResultFormatterFormatErrorLinkResults(t *testing.T) {
&pageResult{
"http://foo.com",
[]*successLinkResult{
{"http://foo.com", 200, 0},
{"http://foo.com", 200},
},
[]*errorLinkResult{
{"http://foo.com", errors.New("500"), 0},
{"http://foo.com", errors.New("500")},
},
0,
},
),
)
Expand All @@ -53,10 +51,9 @@ func TestPageResultFormatterFormatSuccessLinkResultsVerbosely(t *testing.T) {
&pageResult{
"http://foo.com",
[]*successLinkResult{
{"http://foo.com", 200, 0},
{"http://foo.com", 200},
},
nil,
0,
},
),
)
Expand All @@ -68,12 +65,11 @@ func TestPageResultFormatterFormatErrorLinkResultsVerbosely(t *testing.T) {
&pageResult{
"http://foo.com",
[]*successLinkResult{
{"http://foo.com", 200, 0},
{"http://foo.com", 200},
},
[]*errorLinkResult{
{"http://foo.com", errors.New("500"), 0},
{"http://foo.com", errors.New("500")},
},
0,
},
),
)
Expand All @@ -85,11 +81,10 @@ func TestPageResultFormatterSortSuccessLinkResults(t *testing.T) {
&pageResult{
"http://foo.com",
[]*successLinkResult{
{"http://foo.com", 200, 0},
{"http://bar.com", 200, 0},
{"http://foo.com", 200},
{"http://bar.com", 200},
},
nil,
0,
},
),
)
Expand All @@ -102,10 +97,9 @@ func TestPageResultFormatterSortErrorLinkResults(t *testing.T) {
"http://foo.com",
nil,
[]*errorLinkResult{
{"http://foo.com", errors.New("500"), 0},
{"http://bar.com", errors.New("500"), 0},
{"http://foo.com", errors.New("500")},
{"http://bar.com", errors.New("500")},
},
0,
},
),
)
Expand Down
4 changes: 2 additions & 2 deletions page_result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ import (
)

func TestPageResultOK(t *testing.T) {
assert.True(t, (&pageResult{"", nil, nil, 0}).OK())
assert.False(t, (&pageResult{"", nil, []*errorLinkResult{{}}, 0}).OK())
assert.True(t, (&pageResult{"", nil, nil}).OK())
assert.False(t, (&pageResult{"", nil, []*errorLinkResult{{}}}).OK())
}
17 changes: 6 additions & 11 deletions xml_page_result.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package main

type xmlPageResult struct {
Url string `xml:"name,attr"`
Total int `xml:"tests,attr"`
Failures int `xml:"failures,attr"`
Skipped int `xml:"skipped,attr"`
Time float64 `xml:"time,attr"`
Url string `xml:"name,attr"`
Total int `xml:"tests,attr"`
Failures int `xml:"failures,attr"`
Skipped int `xml:"skipped,attr"`
// spell-checker: disable-next-line
Links []*xmlLinkResult `xml:"testcase"`
}

type xmlLinkResult struct {
Url string `xml:"name,attr"`
Time float64 `xml:"time,attr"`
Url string `xml:"name,attr"`
// spell-checker: disable-next-line
Source string `xml:"classname,attr"`
Failure *xmlLinkFailure `xml:"failure"`
Expand All @@ -31,7 +29,6 @@ func newXMLPageResult(pr *pageResult) *xmlPageResult {
&xmlLinkResult{
Url: r.URL,
Source: pr.URL,
Time: r.Elapsed.Seconds(),
},
)
}
Expand All @@ -42,15 +39,13 @@ func newXMLPageResult(pr *pageResult) *xmlPageResult {
&xmlLinkResult{
Url: r.URL,
Source: pr.URL,
Time: r.Elapsed.Seconds(),
Failure: &xmlLinkFailure{Message: r.Error.Error()},
},
)
}

return &xmlPageResult{
Url: pr.URL,
Time: pr.Elapsed.Seconds(),
Url: pr.URL,
// TODO: Consider adding information skipped links, if that can be tracked.
Skipped: 0,
Total: len(ls),
Expand Down

0 comments on commit cf3cdaa

Please sign in to comment.