(t *testing.T)
| 681 | } |
| 682 | |
| 683 | func 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 | } |
nothing calls this directly
no test coverage detected