feat(labs): add the labd provisioner with clone pool, time to live and limits
This commit is contained in:
1 parent
9fdaa62b9b
commit
9385b2ddd4
53 files changed
+14675
-6
No files matched your search
@@ -0,0 +1,53 @@
|
||||
package reaper_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"log/slog"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"lincodex/labd/internal/reaper"
|
||||
)
|
||||
|
||||
type target struct {
|
||||
sweeps atomic.Int32
|
||||
reconciles atomic.Int32
|
||||
}
|
||||
|
||||
func (t *target) Sweep(context.Context) { t.sweeps.Add(1) }
|
||||
|
||||
func (t *target) Reconcile(context.Context) error {
|
||||
t.reconciles.Add(1)
|
||||
return errors.New("lxd unreachable")
|
||||
}
|
||||
|
||||
func TestRunSweepsAndReconcilesUntilCancelled(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
work := &target{}
|
||||
var failures atomic.Int32
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
defer close(done)
|
||||
reaper.Run(ctx, work, reaper.Config{SweepInterval: time.Millisecond, ReconcileInterval: 2 * time.Millisecond},
|
||||
func(err error) {
|
||||
if err != nil {
|
||||
failures.Add(1)
|
||||
}
|
||||
}, slog.New(slog.DiscardHandler))
|
||||
}()
|
||||
deadline := time.Now().Add(5 * time.Second)
|
||||
for work.sweeps.Load() < 3 || failures.Load() < 2 {
|
||||
if time.Now().After(deadline) {
|
||||
t.Fatalf("sweeps %d, failed reconciliations %d", work.sweeps.Load(), failures.Load())
|
||||
}
|
||||
time.Sleep(time.Millisecond)
|
||||
}
|
||||
cancel()
|
||||
select {
|
||||
case <-done:
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatal("Run() did not return after cancellation")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user