#What's the best practice run sharded tests?

1 messages · Page 1 of 1 (latest)

hushed gyro
#

Is there a way to create isolated contexts from within a single @object? The simplest case would be to spawn three isolated sets of:

  • Test database
  • Service
  • e2e runner

I have a dagger function that performs the single shard run, say run-test-shard. It seems like simply defining another function run-tests that calls run-test-shard n times doesn't work, as it seems like it "reuses" service instances already defined by a previous run-test-shard call.

hushed gyro
#

As of now, my workaround is to do three concurrent dagger calls to the e2e test function passing different shard params.

lone locust
# hushed gyro Is there a way to create isolated contexts from within a single @object? The sim...

if you need different instances of the service, you need to change the *dagger.Service object somehow so the engine doesn't re-use the same for optimization reasons.

For example:

type Svc struct{}

func (m *Svc) Test() error {

    wg := errgroup.Group{}

    wg.Go(func() error {
        _, err := run_test_shard(dag.Container(), 1)
        return err
    })
    wg.Go(func() error {
        _, err := run_test_shard(dag.Container(), 2)
        return err
    })

    return wg.Wait()

}

func run_test_shard(c *dagger.Container, shard int) (string, error) {

    svc := dag.Container().From("nginx").
        WithEnvVariable("SHARD", string(shard)).
        WithExposedPort(80).
        AsService()

    return dag.Container().From("alpine:latest").
        WithServiceBinding("nginx", svc).
        WithExec([]string{"apk", "add", "curl"}).
        WithExec([]string{"curl", "nginx"}).Stdout(context.Background())
}

LMK if that makes sense

hushed gyro
#

I'll try it, thanks.