golang.org/x/build@v0.0.0-20240506185731-218518f32b70/internal/coordinator/schedule/fake_schedule.go (about)

     1  // Copyright 2018 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build linux || darwin
     6  
     7  package schedule
     8  
     9  import (
    10  	"context"
    11  	"sync"
    12  
    13  	"golang.org/x/build/buildlet"
    14  	"golang.org/x/build/internal/coordinator/pool/queue"
    15  	"golang.org/x/build/types"
    16  )
    17  
    18  // Fake is a fake scheduler.
    19  type Fake struct {
    20  	mu    sync.Mutex
    21  	state SchedulerState
    22  }
    23  
    24  // NewFake returns a fake scheduler.
    25  func NewFake() *Fake {
    26  	return &Fake{
    27  		state: SchedulerState{
    28  			HostTypes: []SchedulerHostState{},
    29  		},
    30  	}
    31  }
    32  
    33  // State returns the state of the fake scheduler.
    34  func (f *Fake) State() (st SchedulerState) { return f.state }
    35  
    36  // WaiterState is the waiter state of the fake scheduler.
    37  func (f *Fake) WaiterState(waiter *queue.SchedItem) (ws types.BuildletWaitStatus) {
    38  	return types.BuildletWaitStatus{
    39  		Message: "buildlet created",
    40  		Ahead:   0,
    41  	}
    42  }
    43  
    44  // GetBuildlet returns a fake buildlet client for the requested buildlet.
    45  func (f *Fake) GetBuildlet(ctx context.Context, si *queue.SchedItem) (buildlet.Client, error) {
    46  	return &buildlet.FakeClient{}, nil
    47  }