feat: 为执行后端增加独立容量池
This commit is contained in:
@@ -115,3 +115,52 @@ func TestPollerRetriesAssignedTaskBeforeFetchingAnother(t *testing.T) {
|
||||
t.Fatalf("dispatches=%d fetches-before-dispatch=%d declares=%d", dispatcher.calls, dispatcher.fetchesAtSuccess, client.declared)
|
||||
}
|
||||
}
|
||||
|
||||
type blockingPollClient struct {
|
||||
mu sync.Mutex
|
||||
declared int
|
||||
started chan struct{}
|
||||
}
|
||||
|
||||
func (c *blockingPollClient) Declare(context.Context, string, []string) error {
|
||||
c.mu.Lock()
|
||||
c.declared++
|
||||
c.mu.Unlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *blockingPollClient) FetchTask(ctx context.Context, _ int64) (*runnerv1.FetchTaskResponse, error) {
|
||||
c.started <- struct{}{}
|
||||
<-ctx.Done()
|
||||
return nil, ctx.Err()
|
||||
}
|
||||
|
||||
func TestPollerStartsConfiguredNumberOfFetchersAfterOneDeclare(t *testing.T) {
|
||||
client := &blockingPollClient{started: make(chan struct{}, 3)}
|
||||
poller := Poller{
|
||||
Client: client,
|
||||
Scheduler: &Scheduler{TrustDomain: "ddupan.top", Dispatcher: &retryDispatcher{done: make(chan struct{})}},
|
||||
Config: PollerConfig{
|
||||
Version: "dev", Labels: []string{"self-hosted:host", "pod:host", "vm:host"}, Capacity: 3,
|
||||
},
|
||||
}
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
finished := make(chan error, 1)
|
||||
go func() { finished <- poller.Run(ctx) }()
|
||||
for range 3 {
|
||||
select {
|
||||
case <-client.started:
|
||||
case <-time.After(time.Second):
|
||||
t.Fatal("configured fetchers did not start")
|
||||
}
|
||||
}
|
||||
cancel()
|
||||
if err := <-finished; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
client.mu.Lock()
|
||||
defer client.mu.Unlock()
|
||||
if client.declared != 1 {
|
||||
t.Fatalf("declares = %d", client.declared)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user