| 160 | // Create a logger with a tiny channel to test non-blocking behavior |
| 161 | ql := &QueryLogger{ |
| 162 | ch: make(chan QueryLogEntry, 1), |
| 163 | cfg: QueryLogConfig{BatchSize: 1000}, |
| 164 | done: make(chan struct{}), |
| 165 | } |
| 166 | |
| 167 | // Fill the channel |
| 168 | ql.ch <- QueryLogEntry{EventTime: time.Now(), Query: "first"} |
| 169 | |
| 170 | // This should not block |
| 171 | done := make(chan bool, 1) |
| 172 | go func() { |
| 173 | ql.Log(QueryLogEntry{EventTime: time.Now(), Query: "second"}) |
| 174 | done <- true |
| 175 | }() |
| 176 | |
| 177 | select { |
| 178 | case <-done: |
| 179 | // Success - Log returned without blocking |
| 180 | case <-time.After(100 * time.Millisecond): |
| 181 | t.Error("Log() blocked when channel was full") |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | func TestQueryLoggerStopIsIdempotent(t *testing.T) { |
| 186 | db, err := sql.Open("duckdb", ":memory:") |