Skip to content

Commit

Permalink
Fix duplicate visits (#108)
Browse files Browse the repository at this point in the history
* Fix duplicate visits

* Bump version

* Improve format
  • Loading branch information
raviqqe authored Sep 27, 2020
1 parent e388670 commit b85150e
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 12 deletions.
2 changes: 0 additions & 2 deletions arguments.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,13 @@ func getArguments(ss []string) (*arguments, error) {
args.URL = ss[0]

rs, err := compileRegexps(args.RawExcludedPatterns)

if err != nil {
return nil, err
}

args.ExcludedPatterns = rs

hs, err := parseHeaders(args.RawHeaders)

if err != nil {
return nil, err
}
Expand Down
9 changes: 4 additions & 5 deletions checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ func (c *checker) checkPage(p *page) {
ec <- &errorLinkResult{u, err}
}

if !c.onePageOnly &&
p != nil &&
c.linkValidator.Validate(p.URL()) &&
!c.donePages.Add(p.URL().String()) {
if !c.onePageOnly && p != nil && c.linkValidator.Validate(p.URL()) {
c.addPage(p)
}
}(u)
Expand All @@ -91,5 +88,7 @@ func (c *checker) checkPage(p *page) {
}

func (c *checker) addPage(p *page) {
c.daemonManager.Add(func() { c.checkPage(p) })
if !c.donePages.Add(p.URL().String()) {
c.daemonManager.Add(func() { c.checkPage(p) })
}
}
20 changes: 20 additions & 0 deletions checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,23 @@ func TestCheckerFailToCheckPage(t *testing.T) {

assert.False(t, (<-c.Results()).OK())
}

func TestCheckerDoNotCheckSamePageTwice(t *testing.T) {
c := newTestChecker(
newFakeHTTPClient(
func(u *url.URL) (*fakeHTTPResponse, error) {
return newFakeHTTPResponse(200, "http://foo.com", "text/html", nil), nil
},
),
)

go c.Check(newTestPage(t, nil, map[string]error{"http://foo.com": nil}))

i := 0

for range c.Results() {
i++
}

assert.Equal(t, 1, i)
}
1 change: 0 additions & 1 deletion command.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ func newCommand(stdout, stderr io.Writer, terminal bool, f httpClientFactory) *c

func (c *command) Run(args []string) bool {
ok, err := c.runWithError(args)

if err != nil {
c.printError(err)
}
Expand Down
2 changes: 1 addition & 1 deletion configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import "time"

const (
version = "2.0.0"
version = "2.0.1"
agentName = "muffet"
concurrency = 1024
tcpTimeout = time.Minute
Expand Down
3 changes: 2 additions & 1 deletion fasthttp_http_client_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ func (*fasthttpHTTPClientFactory) Create(o httpClientOptions) httpClient {
},
Dial: func(addr string) (net.Conn, error) {
return fasthttp.DialTimeout(addr, tcpTimeout)
}},
},
},
o.MaxRedirections,
o.Timeout,
)
Expand Down
1 change: 0 additions & 1 deletion robots_txt_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func (f *robotsTxtFetcher) Fetch(uu *url.URL) (*robotstxt.RobotsData, error) {
u := *uu
u.Path = "robots.txt"
r, err := f.client.Get(&u, nil)

if err != nil {
return nil, fmt.Errorf("failed to fetch robots.txt: %v", err)
}
Expand Down
1 change: 0 additions & 1 deletion sitemap_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ func (f *sitemapFetcher) Fetch(uu *url.URL) (map[string]struct{}, error) {
u.Path = "sitemap.xml"

r, err := f.client.Get(&u, nil)

if err != nil {
return nil, fmt.Errorf("failed to GET sitemap.xml: %v", err)
}
Expand Down

0 comments on commit b85150e

Please sign in to comment.