mirror of
https://github.com/mudler/LocalAI.git
synced 2026-11-01 10:09:49 -05:00
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>
40 lines
987 B
Go
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())
|
|
})
|
|
})
|