VOL-1334 : Fixed concurrency issues
- Semaphores were added at the different layers of the model
- Made the proxy interfaces more robust
- Eliminated problems while retrieving latest data in concurrent mode
Change-Id: I7854105d7effa10e5cb704f5d9917569ab184f84
diff --git a/db/model/transaction_test.go b/db/model/transaction_test.go
index 7b438b2..0e49f33 100644
--- a/db/model/transaction_test.go
+++ b/db/model/transaction_test.go
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package model
import (
@@ -26,8 +27,8 @@
)
var (
- txTargetDevId string
- txDevId string
+ txTargetDevID string
+ txDevID string
)
func Test_Transaction_1_GetDevices(t *testing.T) {
@@ -39,7 +40,7 @@
t.Error("there are no available devices to retrieve")
} else {
// Save the target device id for later tests
- txTargetDevId = devices.([]interface{})[0].(*voltha.Device).Id
+ txTargetDevID = devices.([]interface{})[0].(*voltha.Device).Id
t.Logf("retrieved devices: %+v", devices)
}
@@ -47,8 +48,8 @@
}
func Test_Transaction_2_AddDevice(t *testing.T) {
- devIdBin, _ := uuid.New().MarshalBinary()
- txDevId = "0001" + hex.EncodeToString(devIdBin)[:12]
+ devIDBin, _ := uuid.New().MarshalBinary()
+ txDevID = "0001" + hex.EncodeToString(devIDBin)[:12]
ports := []*voltha.Port{
{
@@ -63,7 +64,7 @@
}
device := &voltha.Device{
- Id: txDevId,
+ Id: txDevID,
Type: "simulated_olt",
Address: &voltha.Device_HostAndPort{HostAndPort: "1.2.3.4:5555"},
AdminState: voltha.AdminState_PREPROVISIONED,
@@ -75,6 +76,7 @@
if added := addTx.Add("/devices", device); added == nil {
t.Error("Failed to add device")
} else {
+ txTargetDevID = added.(*voltha.Device).Id
t.Logf("Added device : %+v", added)
}
addTx.Commit()
@@ -82,7 +84,7 @@
func Test_Transaction_3_GetDevice_PostAdd(t *testing.T) {
- basePath := "/devices/" + txDevId
+ basePath := "/devices/" + txDevID
getDevWithPortsTx := modelTestConfig.RootProxy.OpenTransaction()
device1 := getDevWithPortsTx.Get(basePath+"/ports", 1, false)
@@ -98,7 +100,7 @@
func Test_Transaction_4_UpdateDevice(t *testing.T) {
updateTx := modelTestConfig.RootProxy.OpenTransaction()
- if retrieved := updateTx.Get("/devices/"+txTargetDevId, 1, false); retrieved == nil {
+ if retrieved := updateTx.Get("/devices/"+txTargetDevID, 1, false); retrieved == nil {
t.Error("Failed to get device")
} else {
var fwVersion int
@@ -106,7 +108,7 @@
fwVersion = 0
} else {
fwVersion, _ = strconv.Atoi(retrieved.(*voltha.Device).FirmwareVersion)
- fwVersion += 1
+ fwVersion++
}
cloned := reflect.ValueOf(retrieved).Elem().Interface().(voltha.Device)
@@ -114,7 +116,7 @@
t.Logf("Before update : %+v", cloned)
// FIXME: The makeBranch passed in function is nil or not being executed properly!!!!!
- if afterUpdate := updateTx.Update("/devices/"+txTargetDevId, &cloned, false); afterUpdate == nil {
+ if afterUpdate := updateTx.Update("/devices/"+txTargetDevID, &cloned, false); afterUpdate == nil {
t.Error("Failed to update device")
} else {
t.Logf("Updated device : %+v", afterUpdate.(Revision).GetData())
@@ -125,7 +127,7 @@
func Test_Transaction_5_GetDevice_PostUpdate(t *testing.T) {
- basePath := "/devices/" + txDevId
+ basePath := "/devices/" + txDevID
getDevWithPortsTx := modelTestConfig.RootProxy.OpenTransaction()
device1 := getDevWithPortsTx.Get(basePath+"/ports", 1, false)
@@ -141,7 +143,7 @@
func Test_Transaction_6_RemoveDevice(t *testing.T) {
removeTx := modelTestConfig.RootProxy.OpenTransaction()
- if removed := removeTx.Remove("/devices/" + txDevId); removed == nil {
+ if removed := removeTx.Remove("/devices/" + txDevID); removed == nil {
t.Error("Failed to remove device")
} else {
t.Logf("Removed device : %+v", removed)
@@ -151,7 +153,7 @@
func Test_Transaction_7_GetDevice_PostRemove(t *testing.T) {
- basePath := "/devices/" + txDevId
+ basePath := "/devices/" + txDevID
getDevTx := modelTestConfig.RootProxy.OpenTransaction()
device := modelTestConfig.RootProxy.Get(basePath, 0, false, "")