Skip to content

Commit

Permalink
fix race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
shogo82148 committed Apr 26, 2022
1 parent fe8f9d8 commit 8e3b25e
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions xray/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,28 @@ import (
)

func TestAddPlugin(t *testing.T) {
org := getPlugins()
defer func() {
muPlugins.Lock()
defer muPlugins.Unlock()
plugins = org
}()
before := len(getPlugins())

// test of races
const n = 10
var wg sync.WaitGroup
wg.Add(n)
for i := 0; i < n; i++ {
go AddPlugin(&xrayPlugin{
sdkVersion: getVersion(),
})
go getPlugins()
go func() {
defer wg.Done()
AddPlugin(&xrayPlugin{
sdkVersion: getVersion(),
})
getPlugins()
}()
}
wg.Wait()

after := len(getPlugins())

Expand Down

0 comments on commit 8e3b25e

Please sign in to comment.