fix: report ErrSearchTimeout when results never hydrate; raise integration selector timeout to 15s

This commit is contained in:
Rustem Kamalov
2026-06-12 19:06:46 +03:00
parent 04db5347a8
commit 976ceeadf4
8 changed files with 19 additions and 7 deletions

View File

@@ -160,7 +160,12 @@ func (baid *Baidu) waitForParsedSearchResults(ctx context.Context, page *rod.Pag
}
return nil, core.ErrParser
}
return nil, nil
// The page never reached a recognizable state: no result containers, no
// captcha or timeout markers. Baidu hydrates result cards client-side and
// can exceed the selector deadline, so report a timeout rather than a
// successful empty SERP — callers must retry/skip, not trust 0 results.
baid.logger.Debug("No result containers or block markers within selector timeout")
return nil, core.ErrSearchTimeout
}
// SearchImage executes a Baidu image search and returns normalized image

View File

@@ -12,6 +12,6 @@ import (
func TestSearchBaidu(t *testing.T) {
ithelper.RunEngineTests(t, func(b *core.Browser) core.SearchEngine {
return New(*b, core.SearchEngineOptions{})
return New(*b, ithelper.EngineOptions())
})
}

View File

@@ -12,6 +12,6 @@ import (
func TestSearchBing(t *testing.T) {
ithelper.RunEngineTests(t, func(b *core.Browser) core.SearchEngine {
return New(*b, core.SearchEngineOptions{})
return New(*b, ithelper.EngineOptions())
})
}

View File

@@ -12,6 +12,6 @@ import (
func TestSearchDuckDuckGo(t *testing.T) {
ithelper.RunEngineTests(t, func(b *core.Browser) core.SearchEngine {
return New(*b, core.SearchEngineOptions{})
return New(*b, ithelper.EngineOptions())
})
}

View File

@@ -12,6 +12,6 @@ import (
func TestSearchEcosia(t *testing.T) {
ithelper.RunEngineTests(t, func(b *core.Browser) core.SearchEngine {
return New(*b, core.SearchEngineOptions{})
return New(*b, ithelper.EngineOptions())
})
}

View File

@@ -12,6 +12,6 @@ import (
func TestSearchGoogle(t *testing.T) {
ithelper.RunEngineTests(t, func(b *core.Browser) core.SearchEngine {
return New(*b, core.SearchEngineOptions{})
return New(*b, ithelper.EngineOptions())
})
}

View File

@@ -47,6 +47,13 @@ func HandleError(t *testing.T, operation string, err error) {
t.Skipf("skipping flaky live %s: %v", operation, err)
}
// EngineOptions returns engine options tuned for live-site integration runs.
// Real SERPs (Baidu especially) hydrate result cards client-side and can take
// well past the 5s default selector timeout on a first visit.
func EngineOptions() core.SearchEngineOptions {
return core.SearchEngineOptions{SelectorTimeout: 15}
}
// CreateBrowser creates a browser configured for integration tests and closes
// it when the test finishes. Respects OPENSERP_INTEGRATION_HEADFUL for
// debugging (browser and page are left open for inspection).

View File

@@ -12,6 +12,6 @@ import (
func TestSearchYandex(t *testing.T) {
ithelper.RunEngineTests(t, func(b *core.Browser) core.SearchEngine {
return New(*b, core.SearchEngineOptions{})
return New(*b, ithelper.EngineOptions())
})
}