Skip to content

Commit

Permalink
Fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
ganglyu committed Dec 9, 2023
1 parent 295a8cb commit bd02b15
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
28 changes: 10 additions & 18 deletions sonic_data_client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,28 +309,20 @@ func TestJsonRemoveNegative(t *testing.T) {
}
}

func TestParseTarget(t *testing.T) {
func TestParseDatabase(t *testing.T) {
var test_paths []*gnmipb.Path
var err error

_, err = ParseTarget("test", test_paths)
if err != nil {
t.Errorf("ParseTarget failed for empty path: %v", err)
}

test_target := "TEST_DB"
path, err := xpath.ToGNMIPath("sonic-db:" + test_target + "/VLAN")
test_target := "APPL_DB"
test_inst := "dpu0"
path, err := xpath.ToGNMIPath("sonic-db:" + test_target + "/" + test_inst + "/VLAN")
test_paths = append(test_paths, path)
target, err := ParseTarget("", test_paths)
target, inst, err := ParseDatabase(nil, test_paths)
if err != nil {
t.Errorf("ParseTarget failed to get target: %v", err)
t.Errorf("ParseDatabase failed to get target: %v", err)
}
if target != test_target {
t.Errorf("ParseTarget return wrong target: %v", target)
}
target, err = ParseTarget("INVALID_DB", test_paths)
if err == nil {
t.Errorf("ParseTarget should fail for conflict")
if target != test_target || inst != test_inst {
t.Errorf("ParseDatabase return wrong target: %v", target)
}
}

Expand Down Expand Up @@ -386,15 +378,15 @@ func ReceiveFromZmq(consumer swsscommon.ZmqConsumerStateTable) (bool) {

func TestZmqReconnect(t *testing.T) {
// create ZMQ server
db := swsscommon.NewDBConnector(APPL_DB_NAME, SWSS_TIMEOUT, false)
db := swsscommon.NewDBConnector(PREV_APPL_DB_NAME, SWSS_TIMEOUT, false)
zmqServer := swsscommon.NewZmqServer("tcp://*:1234")
var TEST_TABLE string = "DASH_ROUTE"
consumer := swsscommon.NewZmqConsumerStateTable(db, TEST_TABLE, zmqServer)

// create ZMQ client side
zmqAddress := "tcp://127.0.0.1:1234"
client := MixedDbClient {
applDB : swsscommon.NewDBConnector(APPL_DB_NAME, SWSS_TIMEOUT, false),
applDB : swsscommon.NewDBConnector(PREV_APPL_DB_NAME, SWSS_TIMEOUT, false),
tableMap : map[string]swsscommon.ProducerStateTable{},
zmqClient : swsscommon.NewZmqClient(zmqAddress),
}
Expand Down
3 changes: 2 additions & 1 deletion sonic_data_client/mixed_db_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (

const REDIS_SOCK string = "/var/run/redis/redis.sock"
const APPL_DB_NAME string = "DPU_APPL_DB"
const PREV_APPL_DB_NAME string = "APPL_DB"
const DASH_TABLE_PREFIX string = "DASH_"
const SWSS_TIMEOUT uint = 0
const MAX_RETRY_COUNT uint = 5
Expand Down Expand Up @@ -1137,7 +1138,7 @@ func (c *MixedDbClient) Set(delete []*gnmipb.Path, replace []*gnmipb.Update, upd
return c.SetConfigDB(delete, replace, update)
} else if c.target == APPL_DB_NAME {
return c.SetDB(delete, replace, update)
} else if c.target == "APPL_DB" {
} else if c.target == PREV_APPL_DB_NAME {
// Backward compatible
return c.SetDB(delete, replace, update)
}
Expand Down

0 comments on commit bd02b15

Please sign in to comment.