Skip to content

Commit

Permalink
tests: increase gpolist command timeout for AD tests (#926)
Browse files Browse the repository at this point in the history
As the AD object is initialized multiple times in tests but only once in
production I opted for the less intuitive approach of defaulting to the
longer timeout and overriding with the production one instead of the
other way around.

This should fix the ad tests we've seen time out in armhf autopkgtests.
  • Loading branch information
GabrielNagy authored Feb 28, 2024
2 parents 5d18611 + d543e42 commit 313d4fe
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
24 changes: 18 additions & 6 deletions internal/ad/ad.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ type AD struct {

withoutKerberos bool
gpoListCmd []string
gpoListTimeout time.Duration
}

type options struct {
Expand All @@ -88,6 +89,7 @@ type options struct {

withoutKerberos bool
gpoListCmd []string
gpoListTimeout time.Duration
}

// Option reprents an optional function to change AD behavior.
Expand All @@ -109,6 +111,14 @@ func WithRunDir(runDir string) Option {
}
}

// WithGpoListTimeout specifies a custom timeout for the adsys-gpolist command.
func WithGpoListTimeout(timeout time.Duration) Option {
return func(o *options) error {
o.gpoListTimeout = timeout
return nil
}
}

// AdsysGpoListCode is the embedded script which request
// Samba to get our GPO list for the given object.
//
Expand All @@ -126,10 +136,11 @@ func New(ctx context.Context, configBackend backends.Backend, hostname string, o

// defaults
args := options{
runDir: consts.DefaultRunDir,
cacheDir: consts.DefaultCacheDir,
gpoListCmd: []string{"python3", "-c", AdsysGpoListCode},
versionID: versionID,
runDir: consts.DefaultRunDir,
cacheDir: consts.DefaultCacheDir,
gpoListCmd: []string{"python3", "-c", AdsysGpoListCode},
versionID: versionID,
gpoListTimeout: 30 * time.Second, // this is used in tests and set to consts.DefaultGpoListTimeout in production
}
// applied options
for _, o := range opts {
Expand Down Expand Up @@ -167,8 +178,9 @@ func New(ctx context.Context, configBackend backends.Backend, hostname string, o
policiesCacheDir: policiesCacheDir,
krb5CacheDir: krb5CacheDir,

downloadables: make(map[string]*downloadable),
gpoListCmd: args.gpoListCmd,
downloadables: make(map[string]*downloadable),
gpoListCmd: args.gpoListCmd,
gpoListTimeout: args.gpoListTimeout,
}, nil
}

Expand Down
1 change: 1 addition & 0 deletions internal/adsysservice/adsysservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ func New(ctx context.Context, opts ...option) (s *Service, err error) {
if args.runDir != "" {
adOptions = append(adOptions, ad.WithRunDir(args.runDir))
}
adOptions = append(adOptions, ad.WithGpoListTimeout(consts.DefaultGpoListTimeout))

hostname, err := os.Hostname()
if err != nil {
Expand Down
9 changes: 8 additions & 1 deletion internal/consts/consts.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// Package consts defines the constants used by the project
package consts

import log "github.com/sirupsen/logrus"
import (
"time"

log "github.com/sirupsen/logrus"
)

var (
// Version is the version of the executable.
Expand Down Expand Up @@ -36,6 +40,9 @@ const (
// DefaultServiceTimeout is the default time in seconds without any active request before the service exits.
DefaultServiceTimeout = 120

// DefaultGpoListTimeout is the default time to wait for the GPO list subcommand to finish.
DefaultGpoListTimeout = 10 * time.Second

// DistroID is the distro ID which can be overridden at build time.
DistroID = "Ubuntu"
)
Expand Down

0 comments on commit 313d4fe

Please sign in to comment.