Add race conditions tests. Fix races.

This commit is contained in:
Leonel Quinteros
2016-06-24 17:45:12 -03:00
parent 6e728a3df5
commit d6f4cbb2d5
5 changed files with 187 additions and 0 deletions

View File

@@ -63,3 +63,60 @@ msgstr[2] "And this is the second plural form: %s"
t.Errorf("Expected 'And this is the second plural form: Variable' but got '%s'", tr)
}
}
func TestPackageRace(t *testing.T) {
// Set PO content
str := `# Some comment
msgid "My text"
msgstr "Translated text"
# More comments
msgid "Another string"
msgstr ""
msgid "One with var: %s"
msgid_plural "Several with vars: %s"
msgstr[0] "This one is the singular: %s"
msgstr[1] "This one is the plural: %s"
msgstr[2] "And this is the second plural form: %s"
`
// Create Locales directory on default location
dirname := path.Clean(library + string(os.PathSeparator) + "en_US")
err := os.MkdirAll(dirname, os.ModePerm)
if err != nil {
t.Fatalf("Can't create test directory: %s", err.Error())
}
// Write PO content to default domain file
filename := path.Clean(dirname + string(os.PathSeparator) + domain + ".po")
f, err := os.Create(filename)
if err != nil {
t.Fatalf("Can't create test file: %s", err.Error())
}
defer f.Close()
_, err = f.WriteString(str)
if err != nil {
t.Fatalf("Can't write to test file: %s", err.Error())
}
// Init sync channels
c1 := make(chan bool)
c2 := make(chan bool)
// Test translations
go func(done chan bool) {
println(Get("My text"))
done <- true
}(c1)
go func(done chan bool) {
println(Get("My text"))
done <- true
}(c2)
println(Get("My text"))
}