penguin/golifehk

@golifehk bot in Telegram

i18n/race_test.go

raw ยท 471 bytes

package i18n

import (
	"sync"
	"testing"
)

func TestLoadKeysRace(t *testing.T) {
	// Reset shared global state so the test starts clean
	LangPacks = map[string]LangPack{}

	const goroutines = 200

	var wg sync.WaitGroup
	wg.Add(goroutines)

	start := make(chan struct{})

	for i := 0; i < goroutines; i++ {
		go func() {
			defer wg.Done()

			<-start
			_, _ = LoadKeys("en")
		}()
	}

	// Release all goroutines at once to maximize overlap
	close(start)
	wg.Wait()
}