Skip to content
Snippets Groups Projects
Commit 4c36bb47 authored by Josh Brooks's avatar Josh Brooks
Browse files

Implement and test GetOldestRoundID

parent f8a4b975
Branches
Tags
1 merge request!58Revert "Modify waiting lock"
...@@ -57,3 +57,8 @@ func (d *Data) GetRound(id int) (*mixmessages.RoundInfo, error) { ...@@ -57,3 +57,8 @@ func (d *Data) GetRound(id int) (*mixmessages.RoundInfo, error) {
func (d *Data) GetLastRoundID() id.Round { func (d *Data) GetLastRoundID() id.Round {
return id.Round(d.rounds.GetNewestId()) return id.Round(d.rounds.GetNewestId())
} }
// Gets the ID of the oldest roundd in the buffer
func (d *Data) GetOldestRoundID() id.Round {
return id.Round(d.rounds.GetOldestId())
}
...@@ -519,6 +519,11 @@ func (i *Instance) GetLastRoundID() id.Round { ...@@ -519,6 +519,11 @@ func (i *Instance) GetLastRoundID() id.Round {
return i.roundData.GetLastRoundID() - 1 return i.roundData.GetLastRoundID() - 1
} }
// Get the oldest round id
func (i *Instance) GetOldestRoundID() id.Round {
return i.roundData.GetOldestRoundID()
}
// Update gateway hosts based on most complete ndf // Update gateway hosts based on most complete ndf
func (i *Instance) UpdateGatewayConnections() error { func (i *Instance) UpdateGatewayConnections() error {
if i.full != nil { if i.full != nil {
......
...@@ -316,6 +316,49 @@ func TestInstance_GetLastUpdateID(t *testing.T) { ...@@ -316,6 +316,49 @@ func TestInstance_GetLastUpdateID(t *testing.T) {
i.GetLastUpdateID() i.GetLastUpdateID()
} }
func TestInstance_GetOldestRoundID(t *testing.T) {
i := Instance{
roundData: ds.NewData(),
}
expectedOldRound := id.Round(0)
_ = i.roundData.UpsertRound(&mixmessages.RoundInfo{ID: uint64(expectedOldRound)})
_ = i.roundData.UpsertRound(&mixmessages.RoundInfo{ID:uint64(2)})
returned := i.GetOldestRoundID()
if returned != expectedOldRound {
t.Errorf("Failed to get oldest round from buffer." +
"\n\tExpected: %v" +
"\n\tReceived: %v", expectedOldRound, returned)
}
}
// Test which forces a full buffer, causing overwriting of old rounds
func TestInstance_GetOldestRoundID_ManyRounds(t *testing.T) {
testInstance := Instance{
roundData: ds.NewData(),
}
// Ensure a circle back in the round buffer
for i := 1; i <= ds.RoundInfoBufLen ; i++ {
_ = testInstance.roundData.UpsertRound(&mixmessages.RoundInfo{ID: uint64(i)})
}
// This will have oldest round as 0, until we reach RoundInfoBufLen, then
// round 0 will be overwritten by the newest round,
// moving the oldest round to round 1
expected := id.Round(1)
returned := testInstance.GetOldestRoundID()
if returned != expected {
t.Errorf("Failed to get oldest round from buffer." +
"\n\tExpected: %v" +
"\n\tReceived: %v", 1, returned)
}
}
func TestInstance_UpdateGatewayConnections(t *testing.T) { func TestInstance_UpdateGatewayConnections(t *testing.T) {
secured, _ := NewSecuredNdf(testutils.NDF) secured, _ := NewSecuredNdf(testutils.NDF)
testManager := connect.NewManagerTesting(t) testManager := connect.NewManagerTesting(t)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment