|
1 | 1 | package cache_test |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "fmt" |
4 | 5 | "os" |
5 | 6 | "path/filepath" |
6 | 7 | "strings" |
@@ -182,6 +183,44 @@ development: |
182 | 183 | }) |
183 | 184 | }) |
184 | 185 |
|
| 186 | + Context("Milvus connection timeouts", func() { |
| 187 | + It("should respect connection timeout when endpoint is unreachable", func() { |
| 188 | + unreachableConfigPath := filepath.Join(tempDir, "milvus-unreachable.yaml") |
| 189 | + unreachableHost := "10.255.255.1" // unroutable address to simulate a hanging dial |
| 190 | + unreachableConfig := fmt.Sprintf(` |
| 191 | +connection: |
| 192 | + host: "%s" |
| 193 | + port: 19530 |
| 194 | + database: "test_cache" |
| 195 | + timeout: 1 |
| 196 | +`, unreachableHost) |
| 197 | + |
| 198 | + err := os.WriteFile(unreachableConfigPath, []byte(unreachableConfig), 0o644) |
| 199 | + Expect(err).NotTo(HaveOccurred()) |
| 200 | + |
| 201 | + done := make(chan struct{}) |
| 202 | + var cacheErr error |
| 203 | + |
| 204 | + go func() { |
| 205 | + defer GinkgoRecover() |
| 206 | + _, cacheErr = cache.NewMilvusCache(cache.MilvusCacheOptions{ |
| 207 | + Enabled: true, |
| 208 | + SimilarityThreshold: 0.85, |
| 209 | + TTLSeconds: 60, |
| 210 | + ConfigPath: unreachableConfigPath, |
| 211 | + }) |
| 212 | + close(done) |
| 213 | + }() |
| 214 | + |
| 215 | + Eventually(done, 2*time.Second, 100*time.Millisecond).Should(BeClosed()) |
| 216 | + Expect(cacheErr).To(HaveOccurred()) |
| 217 | + Expect(cacheErr.Error()).To(Or( |
| 218 | + ContainSubstring("context deadline exceeded"), |
| 219 | + ContainSubstring("timeout"), |
| 220 | + )) |
| 221 | + }) |
| 222 | + }) |
| 223 | + |
185 | 224 | Context("with unsupported backend type", func() { |
186 | 225 | It("should return error for unsupported backend type", func() { |
187 | 226 | config := cache.CacheConfig{ |
|
0 commit comments