Skip to content

Commit

Permalink
Branch just to demonstrate slugify is not concurrency safe
Browse files Browse the repository at this point in the history
Relates to gosimple/slug#51
  • Loading branch information
mhotan committed May 22, 2024
1 parent 52acbd5 commit 02f49ba
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions applicationset/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"path"
"testing"
"time"
"sync"

"github.com/sirupsen/logrus"
logtest "github.com/sirupsen/logrus/hooks/test"
Expand Down Expand Up @@ -1278,6 +1279,28 @@ func TestSlugify(t *testing.T) {
result := SlugifyName(c.length, c.smartTruncate, c.branch)
assert.Equal(t, c.expectedBasePath, result, c.branch)
}

t.Run("slugify with concurrency stressed", func(t *testing.T) {
const numberOfRoutines = 2

for x := 0; x < 1000; x++ {
var wg sync.WaitGroup
wg.Add(numberOfRoutines)
for i := 0; i < numberOfRoutines; i++ {
go func(length int) {
defer wg.Done()
// Call the function concurrently
result := SlugifyName(length, false, "test")
if length == 1 {
assert.Equal(t, "t", result)
} else {
assert.Equal(t, "te", result)
}
}(i+1)
}
wg.Wait()
}
})
}

func TestGetTLSConfig(t *testing.T) {
Expand Down

0 comments on commit 02f49ba

Please sign in to comment.