Skip to content

Commit

Permalink
use SINGLE_ACTIVE_BACKEND for testing AIO?
Browse files Browse the repository at this point in the history
Signed-off-by: Dave Lee <dave@gray101.com>
  • Loading branch information
dave-gray101 committed Dec 17, 2024
1 parent a55011e commit 4201f28
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 46 deletions.
41 changes: 1 addition & 40 deletions tests/e2e-aio/e2e_suite_test.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
package e2e_test

import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"os"
"runtime"
"testing"

"github.com/mudler/LocalAI/core/schema"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/ory/dockertest/v3"
Expand Down Expand Up @@ -76,40 +71,6 @@ var _ = AfterEach(func() {
//Expect(dbClient.Clear()).To(Succeed())
})

func ShutdownModel(modelName string) func() {
return func() {
req := schema.BackendMonitorRequest{
BasicModelRequest: schema.BasicModelRequest{
Model: modelName,
},
}
serialized, err := json.Marshal(req)
Expect(err).To(BeNil())
Expect(serialized).ToNot(BeNil())

// r1, err := http.Post(apiEndpoint+"/backend/monitor", "application/json", bytes.NewReader(serialized))
// Expect(err).To(BeNil())
// Expect(r1).ToNot(BeNil())
// b1, err := io.ReadAll(r1.Body)
// GinkgoWriter.Printf("TEMPORARY MONITOR RESPONSE: %q\n", b1)

resp, err := http.Post(apiEndpoint+"/backend/shutdown", "application/json", bytes.NewReader(serialized))
Expect(err).To(BeNil())
Expect(resp).ToNot(BeNil())
body, err := io.ReadAll(resp.Body)
Expect(err).ToNot(HaveOccurred())
// if a test fails to load the model, we will recieve a 500 error when we try to shut it down.
// We therefore handle both cases seperately
if resp.StatusCode == 500 {
body, err := io.ReadAll(resp.Body)
Expect(err).To(BeNil())
Expect(body).To(ContainSubstring(fmt.Sprintf("%s not found", modelName)), fmt.Sprintf("unexpected response during shutdown: %q", body))
} else {
Expect(resp.StatusCode).To(Equal(200), fmt.Sprintf("failed to shutdown model: %s, response: %+v", body, resp))
}
}
}

func startDockerImage() {
p, err := dockertest.NewPool("")
Expect(err).To(Not(HaveOccurred()))
Expand All @@ -134,7 +95,7 @@ func startDockerImage() {
PortBindings: map[docker.Port][]docker.PortBinding{
"8080/tcp": []docker.PortBinding{{HostPort: apiPort}},
},
Env: []string{"MODELS_PATH=/models", "DEBUG=true", "THREADS=" + fmt.Sprint(proc)},
Env: []string{"MODELS_PATH=/models", "DEBUG=true", "THREADS=" + fmt.Sprint(proc), "LOCALAI_SINGLE_ACTIVE_BACKEND=true"},
Mounts: []string{md + ":/models"},
}

Expand Down
6 changes: 0 additions & 6 deletions tests/e2e-aio/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ var _ = Describe("E2E test", func() {
Model: openai.AdaEmbeddingV2,
},
)
DeferCleanup(ShutdownModel(string(openai.AdaEmbeddingV2)))
Expect(err).ToNot(HaveOccurred())
Expect(len(resp.Data)).To(Equal(1), fmt.Sprint(resp))
Expect(resp.Data[0].Embedding).ToNot(BeEmpty())
Expand Down Expand Up @@ -193,7 +192,6 @@ var _ = Describe("E2E test", func() {
},
},
}})
DeferCleanup(ShutdownModel(model))
Expect(err).ToNot(HaveOccurred())
Expect(len(resp.Choices)).To(Equal(1), fmt.Sprint(resp))
Expect(resp.Choices[0].Message.Content).To(Or(ContainSubstring("wooden"), ContainSubstring("grass")), fmt.Sprint(resp.Choices[0].Message.Content))
Expand All @@ -206,7 +204,6 @@ var _ = Describe("E2E test", func() {
Input: "Hello!",
Voice: openai.VoiceAlloy,
})
DeferCleanup(ShutdownModel(string(openai.TTSModel1)))
Expect(err).ToNot(HaveOccurred())
defer res.Close()

Expand All @@ -227,15 +224,13 @@ var _ = Describe("E2E test", func() {
FilePath: file,
}
resp, err := client.CreateTranscription(context.Background(), req)
DeferCleanup(ShutdownModel(string(openai.Whisper1)))
Expect(err).ToNot(HaveOccurred())
Expect(resp.Text).To(ContainSubstring("This is the"), fmt.Sprint(resp.Text))
})
})
Context("vad", func() {
It("correctly", func() {
modelName := "silero-vad"
DeferCleanup(ShutdownModel(modelName))
req := schema.VADRequest{
BasicModelRequest: schema.BasicModelRequest{
Model: modelName,
Expand Down Expand Up @@ -268,7 +263,6 @@ var _ = Describe("E2E test", func() {
Context("reranker", func() {
It("correctly", func() {
modelName := "jina-reranker-v1-base-en"
DeferCleanup(ShutdownModel(modelName))

req := schema.JINARerankRequest{
BasicModelRequest: schema.BasicModelRequest{
Expand Down

0 comments on commit 4201f28

Please sign in to comment.