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