From 26a73e1aeebd610c2eb2d39542888ffeba118ce6 Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Tue, 21 Jul 2020 20:25:24 +0300
Subject: [PATCH] Remove some duplicate change events

---
 components/structures/src/new_frame.cpp   |  8 ++---
 components/structures/test/frame_unit.cpp | 38 +++++++++++++++++++++++
 2 files changed, 42 insertions(+), 4 deletions(-)

diff --git a/components/structures/src/new_frame.cpp b/components/structures/src/new_frame.cpp
index 69780dab1..a290b25e5 100644
--- a/components/structures/src/new_frame.cpp
+++ b/components/structures/src/new_frame.cpp
@@ -304,11 +304,11 @@ void Frame::forceStore() {
 			d.status = ChannelStatus::INVALID;
 		}
 
-		parent_->change_.trigger(*this, c.first);
-		uint64_t sig = (uint64_t(id()) << 32) + static_cast<unsigned int>(c.first);
-		const auto &i = parent_->change_channel_.find(sig);
+		//parent_->change_.trigger(*this, c.first);
+		//uint64_t sig = (uint64_t(id()) << 32) + static_cast<unsigned int>(c.first);
+		//const auto &i = parent_->change_channel_.find(sig);
 
-		if (i != parent_->change_channel_.end()) i->second.trigger(*this, c.first);
+		//if (i != parent_->change_channel_.end()) i->second.trigger(*this, c.first);
 	}
 }
 
diff --git a/components/structures/test/frame_unit.cpp b/components/structures/test/frame_unit.cpp
index a092b3913..33477e510 100644
--- a/components/structures/test/frame_unit.cpp
+++ b/components/structures/test/frame_unit.cpp
@@ -20,6 +20,7 @@ namespace data {
 class Pool {
 	public:
 	static Frame make(Session *s, FrameID id, uint64_t ts) { return Frame(nullptr, s, id, ts); }
+	static Frame make(Pool *p, Session *s, FrameID id, uint64_t ts) { return Frame(p, s, id, ts); }
 
 	void release(Frame &f);
 
@@ -1067,6 +1068,43 @@ TEST_CASE("ftl::data::Frame change events", "[3.4.1]") {
 		f.store();
 		REQUIRE( event == 1 );
 	}
+
+	SECTION("event on store of foreign change with flush") {
+		Session p;
+		Frame f = Feed::make(&p, FrameID(0,0), 0);
+
+		int event = 0;
+		auto h = f.onChange([&event](Frame &frame, Channel c) {
+			event++;
+			return true;
+		});
+
+		f.createChange<int>(Channel::Pose, ChangeType::FOREIGN);
+		REQUIRE( event == 0 );
+
+		f.store();
+		f.flush();
+		REQUIRE( event == 1 );
+	}
+
+	SECTION("No event on flush of response frame") {
+		ftl::data::Pool p;
+		Session s;
+		Frame f = ftl::data::Pool::make(&p, &s, FrameID(0,0), 0);
+
+		int event = 0;
+		auto h = f.onChange([&event](Frame &frame, Channel c) {
+			event++;
+			return true;
+		});
+
+		{
+			auto response = f.response();
+			REQUIRE( event == 0 );
+			response.create<int>(Channel::Control) = 55;
+		}
+		REQUIRE( event == 0 );
+	}
 }
 
 /* #3.4.2 Not applicable as a unit test of Frame. See #3.2.5 */
-- 
GitLab