Skip to content

fix(parallel): inherit plugin state from parent to support local WithSync - #6

Open
nepridumalnik wants to merge 1 commit into
ozontech:mainfrom
nepridumalnik:main
Open

fix(parallel): inherit plugin state from parent to support local WithSync#6
nepridumalnik wants to merge 1 commit into
ozontech:mainfrom
nepridumalnik:main

Conversation

@nepridumalnik

Copy link
Copy Markdown

Closes #5

What does this PR do?

This PR fixes an issue where the local test option WithSync() was completely ignored and overwritten by global configuration/CLI flags.

How was it fixed?

  • Modified Plugin() method in parallel/plugin.go to properly inherit configuration from the parent plugin if it is present.
  • This ensures that hierarchical state management works as intended by the testo framework architecture, allowing local test options to override global/suite-level configurations.

AI Disclosure

The solution and PR description were prepared with the assistance of Google Gemini. AI was used to analyze the parallel/plugin.go file structure, debug the state-overwriting behavior in the Plugin() method, and format the final code changes according to the framework's architecture.

@ShaDowMak

Copy link
Copy Markdown

I have applied your fixes and in case like this where scope is SuiteTests | Suites | Tests it still runs standalone tests in parallel. It applies parallel for virtual (singleton) suites as Suites scope is set and runs such virtual-suites with single tests in parallel which transitively means running sync tests in parallel.

package examples_test

import (
	"testing"
	"time"

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

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

var _ = testo.Options(parallel.WithScope(parallel.SuiteTests | parallel.Suites | parallel.Tests))

// 1 - sync
// 2 - sync
// 3 - async
func TestSuitelessSequential(t *testing.T) {
	t.Run("1st", testo.Test(func(t T) {
		t.Log("start TestSuitelessSequential 1st")
		time.Sleep(100 * time.Millisecond)
		t.Log("end TestSuitelessSequential 1st")
	}, parallel.WithSync()))

	t.Run("2nd", testo.Test(func(t T) {
		t.Log("start TestSuitelessSequential 2nd")
		time.Sleep(100 * time.Millisecond)
		t.Log("end TestSuitelessSequential 2nd")
	}, parallel.WithSync()))

	t.Run("3rd", testo.Test(func(t T) {
		t.Log("start TestSuitelessSequential 3rd")
		time.Sleep(100 * time.Millisecond)
		t.Log("end TestSuitelessSequential 3rd")
	}))
}
=== RUN   TestSuitelessSequential
=== RUN   TestSuitelessSequential/1st
=== RUN   TestSuitelessSequential/1st/#00
    ./testo-toppings/examples/parallel_comparison/03_testo_suiteless_test.go:20: testo: plugins collected: 1: parallel.PluginParallel
=== PAUSE TestSuitelessSequential/1st/#00
=== CONT  TestSuitelessSequential/1st/#00
=== PAUSE TestSuitelessSequential/1st
=== RUN   TestSuitelessSequential/2nd
=== RUN   TestSuitelessSequential/2nd/#00
    ./testo-toppings/examples/parallel_comparison/03_testo_suiteless_test.go:26: testo: plugins collected: 1: parallel.PluginParallel
=== PAUSE TestSuitelessSequential/2nd/#00
=== CONT  TestSuitelessSequential/2nd/#00
=== PAUSE TestSuitelessSequential/2nd
=== RUN   TestSuitelessSequential/3rd
=== RUN   TestSuitelessSequential/3rd/#00
    ./testo-toppings/examples/parallel_comparison/03_testo_suiteless_test.go:32: testo: plugins collected: 1: parallel.PluginParallel
=== PAUSE TestSuitelessSequential/3rd/#00
=== CONT  TestSuitelessSequential/3rd/#00
=== PAUSE TestSuitelessSequential/3rd
=== CONT  TestSuitelessSequential/1st
=== RUN   TestSuitelessSequential/1st/#00/testo!
=== CONT  TestSuitelessSequential/3rd
=== RUN   TestSuitelessSequential/1st/#00/testo!/1st
=== RUN   TestSuitelessSequential/3rd/#00/testo!
    ./testo-toppings/examples/parallel_comparison/03_testo_suiteless_test.go:21: start TestSuitelessSequential 1st
=== CONT  TestSuitelessSequential/2nd
=== RUN   TestSuitelessSequential/3rd/#00/testo!/3rd
=== RUN   TestSuitelessSequential/2nd/#00/testo!
    ./testo-toppings/examples/parallel_comparison/03_testo_suiteless_test.go:33: start TestSuitelessSequential 3rd
=== RUN   TestSuitelessSequential/2nd/#00/testo!/2nd
    ./testo-toppings/examples/parallel_comparison/03_testo_suiteless_test.go:27: start TestSuitelessSequential 2nd
    ./testo-toppings/examples/parallel_comparison/03_testo_suiteless_test.go:23: end TestSuitelessSequential 1st
    ./testo-toppings/examples/parallel_comparison/03_testo_suiteless_test.go:35: end TestSuitelessSequential 3rd
--- PASS: TestSuitelessSequential/3rd/#00/testo!/3rd (0.10s)
--- PASS: TestSuitelessSequential/1st/#00/testo!/1st (0.10s)
--- PASS: TestSuitelessSequential/3rd/#00/testo! (0.10s)
--- PASS: TestSuitelessSequential/1st/#00/testo! (0.10s)
--- PASS: TestSuitelessSequential/3rd/#00 (0.10s)
--- PASS: TestSuitelessSequential/3rd (0.00s)
--- PASS: TestSuitelessSequential/1st/#00 (0.10s)
--- PASS: TestSuitelessSequential/1st (0.00s)
    ./testo-toppings/examples/parallel_comparison/03_testo_suiteless_test.go:29: end TestSuitelessSequential 2nd
--- PASS: TestSuitelessSequential/2nd/#00/testo!/2nd (0.10s)
--- PASS: TestSuitelessSequential/2nd/#00/testo! (0.10s)
--- PASS: TestSuitelessSequential/2nd/#00 (0.10s)
--- PASS: TestSuitelessSequential/2nd (0.00s)
--- PASS: TestSuitelessSequential (0.00s)
PASS
ok      github.com/ozontech/testo-toppings/examples/parallel_comparison 0.534s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WithSync tests still running as parallel

2 participants