From defe049ac28ad6689231fb12dd1a69eb447336d2 Mon Sep 17 00:00:00 2001 From: zhengchun Date: Thu, 26 Jan 2023 19:58:08 +0800 Subject: [PATCH] add test case for concurrent query --- query_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/query_test.go b/query_test.go index 776cbc5..12ba148 100644 --- a/query_test.go +++ b/query_test.go @@ -7,6 +7,7 @@ import ( "net/http/httptest" "os" "strings" + "sync" "testing" "github.com/antchfx/xpath" @@ -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 := `
a
` + 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 {