Skip to content

Commit

Permalink
add test case for concurrent query
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengchun committed Jan 26, 2023
1 parent e655bcc commit defe049
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http/httptest"
"os"
"strings"
"sync"
"testing"

"github.com/antchfx/xpath"
Expand Down Expand Up @@ -158,6 +159,22 @@ func TestXPathCdUp(t *testing.T) {
}
}

func TestConcurrentQuery(t *testing.T) {
var wg sync.WaitGroup
for i := 0; i < 10; i++ {
wg.Add(1)
go func(i int) {
defer wg.Done()
s := `<html><head></head><body><div>a</div></body>`
doc := loadHTML(s)
if n := FindOne(doc, `//div`); n == nil {
t.Fatalf("should find one but got nil [%d]", i)
}
}(i)
}
wg.Done()
}

func loadHTML(str string) *html.Node {
node, err := Parse(strings.NewReader(str))
if err != nil {
Expand Down

0 comments on commit defe049

Please sign in to comment.