Skip to content

Commit

Permalink
Merge "[FAB-7020] GetLocalMSP cache only on first call"
Browse files Browse the repository at this point in the history
  • Loading branch information
mastersingh24 authored and Gerrit Code Review committed Nov 26, 2017
2 parents 03d1479 + 3e4ad54 commit 704790d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion msp/mgmt/mgmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func GetLocalMSP() msp.MSP {
if err != nil {
mspLogger.Fatalf("Failed to initialize local MSP, received err %+v", err)
}
localMsp = mspInst
localMsp = lclMsp
}
}

Expand Down
21 changes: 21 additions & 0 deletions msp/mgmt/mgmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,24 @@ func TestGetLocalSigningIdentityOrPanic(t *testing.T) {
sid := GetLocalSigningIdentityOrPanic()
assert.NotNil(t, sid)
}

func TestUpdateLocalMspCache(t *testing.T) {
// reset localMsp to force it to be initialized on the first call
localMsp = nil

// first call should initialize local MSP and returned the cached version
firstMsp := GetLocalMSP()
// second call should return the same
secondMsp := GetLocalMSP()
// third call should return the same
thirdMsp := GetLocalMSP()

// the same (non-cached if not patched) instance
if thirdMsp != secondMsp {
t.Fatalf("thirdMsp != secondMsp")
}
// first (cached) and second (non-cached) different unless patched
if firstMsp != secondMsp {
t.Fatalf("firstMsp != secondMsp")
}
}

0 comments on commit 704790d

Please sign in to comment.