aboutsummaryrefslogtreecommitdiff
path: root/splice_modules_test.go
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2016-08-05 22:30:44 -0700
committerColin Cross <ccross@android.com>2016-08-10 16:31:35 -0700
commit49c279ab2614c8bc614f93e13c6137887c0ab395 (patch)
treefa82097ef0f25e91ab83c4b86dcc7c701b5b5966 /splice_modules_test.go
parentf8b5042c86a818f7666ccd40c46be88bc2be0a7a (diff)
downloadblueprint-49c279ab2614c8bc614f93e13c6137887c0ab395.tar.gz
Parallelize BottomUpMutators
Allow BottomUpMutators to run in parallel by calling Parallel() on the return value of RegisterBottomUpMutator. To avoid locking, moves updates of global state into a separate goroutine that receives updates over channels from the mutator goroutines. Change-Id: Ic59b612da9b406cf59ec44940f0c1dee0c051a51
Diffstat (limited to 'splice_modules_test.go')
-rw-r--r--splice_modules_test.go39
1 files changed, 27 insertions, 12 deletions
diff --git a/splice_modules_test.go b/splice_modules_test.go
index cfe905a..a67aeb1 100644
--- a/splice_modules_test.go
+++ b/splice_modules_test.go
@@ -30,73 +30,82 @@ var (
var spliceModulesTestCases = []struct {
in []*moduleInfo
- replace *moduleInfo
+ at int
with []*moduleInfo
out []*moduleInfo
+ outAt int
reallocate bool
}{
{
// Insert at the beginning
in: []*moduleInfo{testModuleA, testModuleB, testModuleC},
- replace: testModuleA,
+ at: 0,
with: []*moduleInfo{testModuleD, testModuleE},
out: []*moduleInfo{testModuleD, testModuleE, testModuleB, testModuleC},
+ outAt: 1,
reallocate: true,
},
{
// Insert in the middle
in: []*moduleInfo{testModuleA, testModuleB, testModuleC},
- replace: testModuleB,
+ at: 1,
with: []*moduleInfo{testModuleD, testModuleE},
out: []*moduleInfo{testModuleA, testModuleD, testModuleE, testModuleC},
+ outAt: 2,
reallocate: true,
},
{
// Insert at the end
in: []*moduleInfo{testModuleA, testModuleB, testModuleC},
- replace: testModuleC,
+ at: 2,
with: []*moduleInfo{testModuleD, testModuleE},
out: []*moduleInfo{testModuleA, testModuleB, testModuleD, testModuleE},
+ outAt: 3,
reallocate: true,
},
{
// Insert over a single element
in: []*moduleInfo{testModuleA},
- replace: testModuleA,
+ at: 0,
with: []*moduleInfo{testModuleD, testModuleE},
out: []*moduleInfo{testModuleD, testModuleE},
+ outAt: 1,
reallocate: true,
},
{
// Insert at the beginning without reallocating
in: []*moduleInfo{testModuleA, testModuleB, testModuleC, nil}[0:3],
- replace: testModuleA,
+ at: 0,
with: []*moduleInfo{testModuleD, testModuleE},
out: []*moduleInfo{testModuleD, testModuleE, testModuleB, testModuleC},
+ outAt: 1,
reallocate: false,
},
{
// Insert in the middle without reallocating
in: []*moduleInfo{testModuleA, testModuleB, testModuleC, nil}[0:3],
- replace: testModuleB,
+ at: 1,
with: []*moduleInfo{testModuleD, testModuleE},
out: []*moduleInfo{testModuleA, testModuleD, testModuleE, testModuleC},
+ outAt: 2,
reallocate: false,
},
{
// Insert at the end without reallocating
in: []*moduleInfo{testModuleA, testModuleB, testModuleC, nil}[0:3],
- replace: testModuleC,
+ at: 2,
with: []*moduleInfo{testModuleD, testModuleE},
out: []*moduleInfo{testModuleA, testModuleB, testModuleD, testModuleE},
+ outAt: 3,
reallocate: false,
},
{
// Insert over a single element without reallocating
in: []*moduleInfo{testModuleA, nil}[0:1],
- replace: testModuleA,
+ at: 0,
with: []*moduleInfo{testModuleD, testModuleE},
out: []*moduleInfo{testModuleD, testModuleE},
+ outAt: 1,
reallocate: false,
},
}
@@ -106,15 +115,21 @@ func TestSpliceModules(t *testing.T) {
in := make([]*moduleInfo, len(testCase.in), cap(testCase.in))
copy(in, testCase.in)
origIn := in
- got := spliceModules(in, testCase.replace, testCase.with)
+ got, gotAt := spliceModules(in, testCase.at, testCase.with)
if !reflect.DeepEqual(got, testCase.out) {
- t.Errorf("test case: %v, %v -> %v", testCase.in, testCase.replace, testCase.with)
+ t.Errorf("test case: %v, %v -> %v", testCase.in, testCase.at, testCase.with)
t.Errorf("incorrect output:")
t.Errorf(" expected: %v", testCase.out)
t.Errorf(" got: %v", got)
}
+ if gotAt != testCase.outAt {
+ t.Errorf("test case: %v, %v -> %v", testCase.in, testCase.at, testCase.with)
+ t.Errorf("incorrect index:")
+ t.Errorf(" expected: %d", testCase.outAt)
+ t.Errorf(" got: %d", gotAt)
+ }
if sameArray(origIn, got) != !testCase.reallocate {
- t.Errorf("test case: %v, %v -> %v", testCase.in, testCase.replace, testCase.with)
+ t.Errorf("test case: %v, %v -> %v", testCase.in, testCase.at, testCase.with)
not := ""
if !testCase.reallocate {
not = " not"