Skip to content

Commit defe049

Browse files
committed
add test case for concurrent query
1 parent e655bcc commit defe049

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

query_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"net/http/httptest"
88
"os"
99
"strings"
10+
"sync"
1011
"testing"
1112

1213
"github.com/antchfx/xpath"
@@ -158,6 +159,22 @@ func TestXPathCdUp(t *testing.T) {
158159
}
159160
}
160161

162+
func TestConcurrentQuery(t *testing.T) {
163+
var wg sync.WaitGroup
164+
for i := 0; i < 10; i++ {
165+
wg.Add(1)
166+
go func(i int) {
167+
defer wg.Done()
168+
s := `<html><head></head><body><div>a</div></body>`
169+
doc := loadHTML(s)
170+
if n := FindOne(doc, `//div`); n == nil {
171+
t.Fatalf("should find one but got nil [%d]", i)
172+
}
173+
}(i)
174+
}
175+
wg.Done()
176+
}
177+
161178
func loadHTML(str string) *html.Node {
162179
node, err := Parse(strings.NewReader(str))
163180
if err != nil {

0 commit comments

Comments
 (0)