Skip to content

Commit

Permalink
Added concurrent shims test for #1
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaSjoding committed Mar 8, 2019
1 parent 77b0236 commit 7a6ecaa
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions shim_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package comshim_test

import (
"runtime"
"sync"
"testing"

"github.com/go-ole/go-ole/oleutil"
"github.com/scjalliance/comshim"
)

func TestConcurrentShims(t *testing.T) {
var maxRounds int
if testing.Short() {
maxRounds = 64
} else {
maxRounds = 256
}

// Vary the number of threads
for procs := 1; procs < 11; procs++ {
runtime.GOMAXPROCS(procs)

// Vary the number of shims
for rounds := 1; rounds <= maxRounds; rounds *= 2 {
wg := sync.WaitGroup{}
for i := 0; i < rounds; i++ {
wg.Add(1)
go func(i int) {
defer wg.Done()

comshim.Add(1)
defer comshim.Done()

obj, err := oleutil.CreateObject("WbemScripting.SWbemLocator")
if err != nil {
t.Error(err)
} else {
defer obj.Release()
}
}(i)
}
wg.Wait()
}
}
}

0 comments on commit 7a6ecaa

Please sign in to comment.