MCPcopy Create free account
hub / github.com/bytebase/bytebase / TestQueryDatabase_Timeout

Function TestQueryDatabase_Timeout

backend/api/mcp/tool_query_test.go:683–709  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

681}
682
683func TestQueryDatabase_Timeout(t *testing.T) {
684 databases := []map[string]any{
685 makeDatabase("instances/prod-pg/databases/employee_db", "instances/prod-pg", "projects/hr-system", "POSTGRES", "ds-admin-1"),
686 }
687 handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
688 if strings.Contains(r.URL.Path, "SQLService/Query") {
689 // Sleep longer than the context timeout.
690 time.Sleep(500 * time.Millisecond)
691 w.WriteHeader(http.StatusOK)
692 return
693 }
694 mockListDatabases(databases).ServeHTTP(w, r)
695 })
696 s := newTestServerWithMock(t, handler)
697
698 // Use a very short timeout.
699 ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
700 defer cancel()
701
702 resolved := &resolvedDatabase{
703 resourceName: "instances/prod-pg/databases/employee_db",
704 dataSourceID: "ds-admin-1",
705 }
706 _, err := s.executeQuery(ctx, resolved, "SELECT 1", 100)
707 require.Error(t, err)
708 require.Contains(t, err.Error(), "QUERY_ERROR")
709}

Callers

nothing calls this directly

Calls 6

mockListDatabasesFunction · 0.85
newTestServerWithMockFunction · 0.85
cancelFunction · 0.85
executeQueryMethod · 0.80
makeDatabaseFunction · 0.70
ErrorMethod · 0.45

Tested by

no test coverage detected