parallel

package
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 29, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

README

🤹 Parallel

Testo plugin for making all tests parallel by default.

Go has great support for parallel tests. But marking a test as parallel requires an explicit t.Parallel() call. This plugin does that for you!

Quick Start

go get github.com/ozontech/testo-toppings

Add it to your T:

package main

import (
	"github.com/ozontech/testo"
	"github.com/ozontech/testo-toppings/parallel"
)

type T struct {
	*testo.T
	*parallel.PluginParallel
}

All your tests are now parallel by default!

[!NOTE] With this plugin enabled, explicit calls to t.Parallel() are no-op.

Use annotations to mark any test as synchronous:

var _ = testo.For(Suite.TestFoo, parallel.WithSync())

func (Suite) TestFoo(t T) {
    // ...
}

To make all tests synchronous pass -parallel.sync flag to go test:

go test ./... -parallel.sync

Scopes

Tests can be parallelized to a different extents.

This is configured through "scopes".

Available scopes:

const (
	// SuiteTests is a [Scope] that covers suite tests.
	//
	// For example:
	//
	// 	func (Suite) TestA(t T) { ... }
	// 	func (Suite) TestB(t T) { ... }
	//
	// Tests A & B will be marked as parallel.
	//
	// This is a default value.
	SuiteTests Scope = 1 << iota

	// Suites is a [Scope] that covers suites but not their tests.
	//
	// For example:
	//
	// 	func Test(t *testing.T) {
	//		testo.RunSuite(t, new(Suite))
	//		testo.RunSuite(t, new(OtherSuite))
	// 	}
	//
	// Both of these suites will be run in parallel.
	Suites

	// Tests is a [Scope] that covers native tests.
	//
	// For example:
	//
	// 	func TestA(t *testing.T) {
	//		testo.RunSuite(t, new(Suite))
	// 	}
	//
	// 	func TestA(t *testing.T) {
	//		testo.RunSuite(t, new(OtherSuite))
	// 	}
	//
	// Tests A & B will be run in parallel.
	Tests
)

Scopes are configured with WithScope option:

// WithScope sets a [Scope] of a plugin.
// Scope defines to what extent tests should become parallel.
//
// This plugin, by default, marks as parallel only suites' tests.
// You may want to extend its reach to suites as a whole, so that,
// say, multiple runs to [testo.RunSuite] will also run in parallel.
//
//	parallel.WithScope(parallel.SuiteTests | parallel.Suites)
//
// It's also possible to mark "native" tests as parallel by adding a [Tests] scope.
//
//	parallel.WithScope(parallel.SuiteTests | parallel.Suites | parallel.Tests)
func WithScope(scope Scope) testoplugin.Option

Documentation

Overview

Package parallel provides plugin to mark tests as parallel by default.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithScope added in v1.1.0

func WithScope(scope Scope) testoplugin.Option

WithScope sets a Scope of a plugin. Scope defines to what extent tests should become parallel.

This plugin, by default, marks as parallel only suites' tests. You may want to extend its reach to suites as a whole, so that, say, multiple runs to testo.RunSuite will also run in parallel.

parallel.WithScope(parallel.SuiteTests | parallel.Suites)

It's also possible to mark "native" tests as parallel by adding a Tests scope.

parallel.WithScope(parallel.SuiteTests | parallel.Suites | parallel.Tests)

func WithSync

func WithSync() testoplugin.Option

WithSync signals that this test is to be run in sync with (and only with) other sync tests.

Types

type PluginParallel

type PluginParallel struct {
	*testo.T
	// contains filtered or unexported fields
}

PluginParallel marks all tests as parallel by default.

func (*PluginParallel) Plugin

func (p *PluginParallel) Plugin(
	_ testoplugin.Plugin,
	options ...testoplugin.Option,
) testoplugin.Spec

Plugin implements testoplugin.Plugin.

type Scope added in v1.1.0

type Scope uint8

Scope defines to what extent tests should become parallel.

const (
	// SuiteTests is a [Scope] that covers suite tests.
	//
	// For example:
	//
	// 	func (Suite) TestA(t T) { ... }
	// 	func (Suite) TestB(t T) { ... }
	//
	// Tests A & B will be marked as parallel.
	//
	// This is a default value.
	SuiteTests Scope = 1 << iota

	// Suites is a [Scope] that covers suites but not their tests.
	//
	// For example:
	//
	// 	func Test(t *testing.T) {
	//		testo.RunSuite(t, new(Suite))
	//		testo.RunSuite(t, new(OtherSuite))
	// 	}
	//
	// Both of these suites will be run in parallel.
	Suites

	// Tests is a [Scope] that covers native tests.
	//
	// For example:
	//
	// 	func TestA(t *testing.T) {
	//		testo.RunSuite(t, new(Suite))
	// 	}
	//
	// 	func TestA(t *testing.T) {
	//		testo.RunSuite(t, new(OtherSuite))
	// 	}
	//
	// Tests A & B will be run in parallel.
	Tests
)

Available scopes. Scopes can be combined using bitmasks:

const All = SuiteTests | Suites | Tests

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL