Check for pending associations
When the mapper is adding a new D-Bus path to its path map,
either via an introspect or in the interfacesAdded handler,
check if that new path has an outstanding pending association.
If it does, then create the 2 real association paths and
remove that entry from the pending associations maps.
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I2da8109b5cba8596eb0c14a6af0d377472ca4145
diff --git a/src/test/associations.cpp b/src/test/associations.cpp
index 5f87020..dee991d 100644
--- a/src/test/associations.cpp
+++ b/src/test/associations.cpp
@@ -444,3 +444,30 @@
removeFromPendingAssociations(DEFAULT_ENDPOINT, assocMaps);
EXPECT_EQ(assocMaps.pending.size(), 0);
}
+
+// Test moving a pending association to a real one
+TEST_F(TestAssociations, checkIfPending)
+{
+ AssociationMaps assocMaps;
+ interface_map_type interfaceMap = {
+ {DEFAULT_SOURCE_PATH, {{DEFAULT_DBUS_SVC, {"a"}}}},
+ {DEFAULT_ENDPOINT, {{DEFAULT_DBUS_SVC, {"b"}}}}};
+
+ addPendingAssociation(DEFAULT_SOURCE_PATH, "inventory", DEFAULT_ENDPOINT,
+ "error", DEFAULT_DBUS_SVC, assocMaps);
+ EXPECT_EQ(assocMaps.pending.size(), 1);
+
+ // Move the pending association to a real association
+ checkIfPendingAssociation(DEFAULT_SOURCE_PATH, interfaceMap, assocMaps,
+ *server);
+
+ EXPECT_TRUE(assocMaps.pending.empty());
+ EXPECT_EQ(assocMaps.owners.size(), 1);
+ EXPECT_EQ(assocMaps.ifaces.size(), 2);
+
+ // This shouldn't do anything, since /new/path isn't pending
+ checkIfPendingAssociation("/new/path", interfaceMap, assocMaps, *server);
+ EXPECT_TRUE(assocMaps.pending.empty());
+ EXPECT_EQ(assocMaps.owners.size(), 1);
+ EXPECT_EQ(assocMaps.ifaces.size(), 2);
+}