99"strings"
1010"sync"
1111"sync/atomic"
12- "testing"
1312"time"
1413
1514"github.com/dustin/go-humanize"
@@ -138,17 +137,11 @@ func (e *Executor) Run() {
138137}()
139138}
140139
141- func (e * Executor )hasAvailableProvisioners (ctx context.Context ,tx database.Store ,ws database.Workspace ,templateVersionJob database.ProvisionerJob ) (bool ,error ) {
140+ func (e * Executor )hasAvailableProvisioners (ctx context.Context ,tx database.Store ,t time. Time , ws database.Workspace ,templateVersionJob database.ProvisionerJob ) (bool ,error ) {
142141if e .SkipProvisionerCheck {
143142return true ,nil
144143}
145144
146- // Use a shorter stale interval for tests
147- staleInterval := provisionerdserver .StaleInterval
148- if testing .Testing () {
149- staleInterval = TestingStaleInterval
150- }
151-
152145// Get eligible provisioner daemons for this workspace's template
153146provisionerDaemons ,err := tx .GetProvisionerDaemonsByOrganization (ctx , database.GetProvisionerDaemonsByOrganizationParams {
154147OrganizationID :ws .OrganizationID ,
@@ -159,11 +152,10 @@ func (e *Executor) hasAvailableProvisioners(ctx context.Context, tx database.Sto
159152}
160153
161154// Check if any provisioners are active (not stale)
162- now := dbtime .Now ()
163155for _ ,pd := range provisionerDaemons {
164156if pd .LastSeenAt .Valid {
165- age := now .Sub (pd .LastSeenAt .Time )
166- if age <= staleInterval {
157+ age := t .Sub (pd .LastSeenAt .Time )
158+ if age <= provisionerdserver . StaleInterval {
167159return true ,nil
168160}
169161}
@@ -327,7 +319,7 @@ func (e *Executor) runOnce(t time.Time) Stats {
327319}
328320
329321// Before creating the workspace build, check for available provisioners
330- hasProvisioners ,err := e .hasAvailableProvisioners (e .ctx ,tx ,ws ,templateVersionJob )
322+ hasProvisioners ,err := e .hasAvailableProvisioners (e .ctx ,tx ,t , ws ,templateVersionJob )
331323if err != nil {
332324return xerrors .Errorf ("check provisioner availability: %w" ,err )
333325}