Skip to content

Commit

Permalink
MFW-2299: Prune the in-memory device data in reportd
Browse files Browse the repository at this point in the history
  • Loading branch information
iramasamy committed Oct 6, 2022
1 parent 50545d9 commit b3dad10
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 7 deletions.
44 changes: 43 additions & 1 deletion services/discovery/devices_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (suite *DeviceListTestSuite) SetupTest() {
}
}

//TestListing tests that applying various predicates to the list
// TestListing tests that applying various predicates to the list
// works.
func (suite *DeviceListTestSuite) TestListing() {

Expand Down Expand Up @@ -104,6 +104,13 @@ func (suite *DeviceListTestSuite) TestListing() {
expectedListMacs: []string{},
description: "There are no devices in the list that have an update time within 20 minutes and are not local.",
},
{
predicates: []ListPredicate{
LastUpdateOlderThanDuration(time.Hour * 24),
},
expectedListMacs: []string{suite.mac4},
description: "List of macs with an update time older than 24 hours should be mac4",
},
}
// duplicate the tests for concurrent testing.
testsDuplicated := append(tests, tests...)
Expand Down Expand Up @@ -142,6 +149,7 @@ func (suite *DeviceListTestSuite) TestListing() {
}
wg.Done()
}()

}
wg.Wait()
}
Expand Down Expand Up @@ -252,6 +260,40 @@ func (suite *DeviceListTestSuite) TestBroadcastInsertion() {
suite.Equal(suite.devicesTable, deviceList.Devices, "Adding broadcast discovery entry.")
}

// Test clean device entry
func (suite *DeviceListTestSuite) TestCleanDeviceEntry() {

var deviceList DevicesList
var count uint32
deviceList.Devices = map[string]*DeviceEntry{}

for _, entry := range suite.devicesTable {
deviceList.Devices[entry.MacAddress] = &DeviceEntry{
DiscoveryEntry: disco.DiscoveryEntry{
IPv4Address: entry.IPv4Address,
MacAddress: entry.MacAddress,
LastUpdate: entry.LastUpdate,
},
}
count++
}
//Clean entries which are 48 hours older
predicates1 := []ListPredicate{
LastUpdateOlderThanDuration(time.Hour * 48),
}
deviceList.CleanOldDeviceEntry(predicates1...)
//No entries should be deleted from the list, because no entries with LastUpdate older than 48 hours
suite.EqualValues(count, len(deviceList.Devices), "Cleaned 48 hours older entry")

//Clean entries which are 24 hours older
predicates2 := []ListPredicate{
LastUpdateOlderThanDuration(time.Hour * 24),
}
deviceList.CleanOldDeviceEntry(predicates2...)
//One device entry should be deleted from the device list which entry has LastUpdate with >24 hours
suite.EqualValues(count-1, len(deviceList.Devices), "Cleaned 24 hours older entry")
}

// TestMarshallingList tests that we can marshal a list of devices
// obtained via the ApplyToDeviceList function to JSON without getting
// an exception.
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion structs/protocolbuffers/Discoverd/Discovery.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion structs/protocolbuffers/SessionEvent/SessionEvent.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion structs/protocolbuffers/ZMQRequest/ZMQRequest.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b3dad10

Please sign in to comment.