Files
LocalAI/core/backend/global_admission_test.go
T
Richard Palethorpe 799cc9f211 feat: bound global admission and expose running backend traces (#11560)
feat: bound backend admission and expose running traces

Add process-wide backend execution admission without blocking UI or administrative HTTP work. Represent backend operations while they are in flight, surface running traces with immediate log links, and tie streaming admission leases to the gRPC receive lifecycle.

Assisted-by: OpenAI Codex: GPT-5

Signed-off-by: Richard Palethorpe <io@richiejp.com>
2026-08-18 08:56:59 +02:00

40 lines
987 B
Go

// SPDX-License-Identifier: MIT
package backend_test
import (
"errors"
"github.com/mudler/LocalAI/core/backend"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("global backend admission", func() {
BeforeEach(func() {
backend.ConfigureGlobalBackendAdmission(1)
})
It("rejects excess backend work without queueing", func() {
release, err := backend.AcquireGlobalBackendSlot()
Expect(err).NotTo(HaveOccurred())
Expect(backend.GlobalBackendInFlight()).To(Equal(1))
_, err = backend.AcquireGlobalBackendSlot()
var capacityErr *backend.BackendAdmissionError
Expect(errors.As(err, &capacityErr)).To(BeTrue())
Expect(capacityErr.Limit).To(Equal(1))
release()
Expect(backend.GlobalBackendInFlight()).To(BeZero())
})
It("makes release idempotent", func() {
release, err := backend.AcquireGlobalBackendSlot()
Expect(err).NotTo(HaveOccurred())
release()
release()
Expect(backend.GlobalBackendInFlight()).To(BeZero())
})
})