Skip to content

Commit 8aaf62a

Browse files
authored
test: Redis CI bootstrap (#751)
Signed-off-by: cryo <[email protected]>
1 parent 70a4e00 commit 8aaf62a

File tree

3 files changed

+102
-1
lines changed

3 files changed

+102
-1
lines changed

.github/workflows/test-and-build.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ jobs:
113113
114114
echo "Milvus is ready at localhost:19530"
115115
docker ps --filter "name=milvus-semantic-cache"
116+
117+
- name: Start Redis service
118+
run: |
119+
echo "Starting Redis Stack..."
120+
make start-redis
116121
117122
- name: Run semantic router tests
118123
run: make test
@@ -123,6 +128,13 @@ jobs:
123128
LD_LIBRARY_PATH: ${{ github.workspace }}/candle-binding/target/release
124129
MILVUS_URI: localhost:19530
125130
SKIP_MILVUS_TESTS: false
131+
SKIP_REDIS_TESTS: false
132+
133+
- name: Clean Redis service
134+
if: always()
135+
run: |
136+
echo "Stopping Redis container and cleaning data..."
137+
make clean-redis
126138
127139
- name: Stop Milvus service
128140
if: always()

src/semantic-router/pkg/cache/cache_test.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,94 @@ development:
189189
})
190190
})
191191

192+
Context("with Redis backend", func() {
193+
var redisConfigPath string
194+
195+
BeforeEach(func() {
196+
if os.Getenv("SKIP_REDIS_TESTS") == "true" {
197+
Skip("Redis tests skipped due to SKIP_REDIS_TESTS=true")
198+
}
199+
200+
redisConfigPath = filepath.Join(tempDir, "redis.yaml")
201+
redisConfig := `
202+
connection:
203+
host: "localhost"
204+
port: 6379
205+
database: 0
206+
timeout: 30
207+
208+
index:
209+
name: "test_semantic_cache"
210+
prefix: "doc:"
211+
vector_field:
212+
name: "embedding"
213+
dimension: 384
214+
metric_type: "COSINE"
215+
index_type: "HNSW"
216+
params:
217+
M: 16
218+
efConstruction: 64
219+
220+
search:
221+
topk: 1
222+
223+
logging:
224+
enable_query_log: false
225+
enable_metrics: false
226+
227+
development:
228+
drop_index_on_startup: true
229+
auto_create_index: true
230+
verbose_errors: true
231+
`
232+
err := os.WriteFile(redisConfigPath, []byte(redisConfig), 0o644)
233+
Expect(err).NotTo(HaveOccurred())
234+
})
235+
236+
It("should create Redis cache backend successfully with valid config", func() {
237+
config := CacheConfig{
238+
BackendType: RedisCacheType,
239+
Enabled: true,
240+
SimilarityThreshold: 0.8,
241+
TTLSeconds: 3600,
242+
BackendConfigPath: redisConfigPath,
243+
EmbeddingModel: "bert",
244+
}
245+
246+
backend, err := NewCacheBackend(config)
247+
248+
if err != nil {
249+
if strings.Contains(err.Error(), "failed to connect to Redis") ||
250+
strings.Contains(err.Error(), "connection refused") ||
251+
strings.Contains(err.Error(), "failed to initialize index") {
252+
Skip("Redis server not available: " + err.Error())
253+
}
254+
Expect(err).NotTo(HaveOccurred())
255+
} else {
256+
Expect(backend).NotTo(BeNil())
257+
Expect(backend.IsEnabled()).To(BeTrue())
258+
Expect(backend.Close()).To(Succeed())
259+
}
260+
})
261+
262+
It("should handle disabled Redis cache", func() {
263+
config := CacheConfig{
264+
BackendType: RedisCacheType,
265+
Enabled: false,
266+
SimilarityThreshold: 0.8,
267+
TTLSeconds: 3600,
268+
BackendConfigPath: redisConfigPath,
269+
EmbeddingModel: "bert",
270+
}
271+
272+
backend, err := NewCacheBackend(config)
273+
Expect(err).NotTo(HaveOccurred())
274+
Expect(backend).NotTo(BeNil())
275+
Expect(backend.IsEnabled()).To(BeFalse())
276+
Expect(backend.Close()).To(Succeed())
277+
})
278+
})
279+
192280
Context("Milvus connection timeouts", func() {
193281
It("should respect connection timeout when endpoint is unreachable", func() {
194282
unreachableConfigPath := filepath.Join(tempDir, "milvus-unreachable.yaml")

tools/make/build-run-test.mk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@ run-router-e2e: build-router download-models
3030
./bin/router -config=config/testing/config.e2e.yaml
3131

3232
# Unit test semantic-router
33-
# By default, Milvus tests are skipped. To enable them, set SKIP_MILVUS_TESTS=false
33+
# By default, Milvus and Redis tests are skipped. To enable them, set SKIP_MILVUS_TESTS=false and/or SKIP_REDIS_TESTS=false
3434
# Example: make test-semantic-router SKIP_MILVUS_TESTS=false
3535
test-semantic-router: ## Run unit tests for semantic-router (set SKIP_MILVUS_TESTS=false to enable Milvus tests)
3636
test-semantic-router: build-router
3737
@$(LOG_TARGET)
3838
@export LD_LIBRARY_PATH=${PWD}/candle-binding/target/release && \
3939
export SKIP_MILVUS_TESTS=$${SKIP_MILVUS_TESTS:-true} && \
40+
export SKIP_REDIS_TESTS=$${SKIP_REDIS_TESTS:-true} && \
4041
export SR_TEST_MODE=true && \
4142
cd src/semantic-router && CGO_ENABLED=1 go test -v ./...
4243

0 commit comments

Comments
 (0)