Skip to content

Run sequential sub-tests inside parallel tests #14

@gnuletik

Description

@gnuletik

Hi,

Thanks for this linter! I just discovered it by upgrading golangci-lint.
However, when running it on our codebase, it seems that some use case should not be an error.

We may want run multiple Test in parallel which contains sequential sub-tests.

For example:

func TestGet(t *testing.T) {
  t.Paralell()
  // creates a new isolated database like
  // https://github.com/allaboutapps/integresql
  db := createNewDB(t)

  t.Run("GetEmpty", func () {
    // make a GET request and check that it returns an empty slice
  })

  t.Run("GetOne", func() {
    // create a row in database
    // make a GET request and check that it returns a slice of size 1
  })
}

func TestUpdate(t *testing.T) {
  t.Parallel()
  db := createNewDB(t)

  t.Run("UpdateFirstName", func() {
    // make a PATCH request and check that only the first name was updated
  })

  t.Run("UpdateLastName", func () {
    // make a PATCH request and check that only the last name was updated
  })
}
TestGet's subtests should call t.Parallel (tparallel)
TestUpdate's subtests should call t.Parallel (tparallel)

But this example does not seems to be an inappropriate usage of t.Parallel().
We want to be able to run TestGet and TestUpdate in parallel (because they run with their own database) without running their subtests in parallel (because they use the same database instance).

We could also have use-cases for sequential tests with parallel sub-tests.

Or am I missing something?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions