PERF: speed up spec (#794)

~500ms -> ~100ms

It is still not a super fast spec given search is not free, but
it is a bit faster and clearer
This commit is contained in:
Sam 2024-09-04 16:14:32 +10:00 committed by GitHub
parent cabecb801e
commit a5b5c3bebe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 20 additions and 6 deletions

View File

@ -63,12 +63,26 @@ describe DiscourseAi::Embeddings::EmbeddingsController do
context "when rate limiting is enabled" do
before { RateLimiter.enable }
it "will not rate limit API for hyde search" do
10.times do |i|
use_redis_snapshotting
it "will rate limit correctly" do
stub_const(subject.class, :MAX_HYDE_SEARCHES_PER_MINUTE, 1) do
stub_const(subject.class, :MAX_SEARCHES_PER_MINUTE, 2) do
query = "test #{SecureRandom.hex}"
stub_embedding(query)
get "/discourse-ai/embeddings/semantic-search.json?q=#{query}&hyde=false"
expect(response.status).to eq(200)
query = "test #{SecureRandom.hex}"
stub_embedding(query)
get "/discourse-ai/embeddings/semantic-search.json?q=#{query}&hyde=false"
expect(response.status).to eq(200)
query = "test #{SecureRandom.hex}"
stub_embedding(query)
get "/discourse-ai/embeddings/semantic-search.json?q=#{query}&hyde=false"
expect(response.status).to eq(429)
end
end
end
end