tc39_race_test.go 622 B

1234567891011121314151617181920212223242526272829303132
  1. //go:build race
  2. // +build race
  3. package goja
  4. import (
  5. "testing"
  6. )
  7. const (
  8. tc39MaxTestGroupSize = 8000 // to prevent race detector complaining about too many goroutines
  9. )
  10. func (ctx *tc39TestCtx) runTest(name string, f func(t *testing.T)) {
  11. ctx.testQueue = append(ctx.testQueue, tc39Test{name: name, f: f})
  12. if len(ctx.testQueue) >= tc39MaxTestGroupSize {
  13. ctx.flush()
  14. }
  15. }
  16. func (ctx *tc39TestCtx) flush() {
  17. ctx.t.Run("tc39", func(t *testing.T) {
  18. for _, tc := range ctx.testQueue {
  19. tc := tc
  20. t.Run(tc.name, func(t *testing.T) {
  21. t.Parallel()
  22. tc.f(t)
  23. })
  24. }
  25. })
  26. ctx.testQueue = ctx.testQueue[:0]
  27. }