mirror of
https://github.com/status-im/status-go.git
synced 2025-01-09 14:16:21 +00:00
e2cab1a8ae
- Extracted `community_events_factory.go` - Introduced `eventsProcessor` - Improved processing logic order - Improved events filtering - Introduced concept of `EventTypeID` to prevent redundant events handling - Added sanity check before events appliance when reading community from database - Removed reject&re-apply scheme (no more ping-pong issue) - Fixed and added more variants to eventual consistency test fixes: status-im/status-desktop#13387 fixes: status-im/status-desktop#13388
70 lines
2.1 KiB
Go
70 lines
2.1 KiB
Go
package communities
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
"github.com/status-im/status-go/protocol/protobuf"
|
|
)
|
|
|
|
func TestEventsProcessorSuite(t *testing.T) {
|
|
suite.Run(t, new(EventsProcessorSuite))
|
|
}
|
|
|
|
type EventsProcessorSuite struct {
|
|
suite.Suite
|
|
}
|
|
|
|
func (s *EventsProcessorSuite) TestRetainNewestEventsPerPropertyTypeID() {
|
|
processor := &eventsProcessor{
|
|
eventsToApply: []CommunityEvent{
|
|
CommunityEvent{
|
|
CommunityEventClock: 1,
|
|
Type: protobuf.CommunityEvent_COMMUNITY_EDIT,
|
|
},
|
|
CommunityEvent{
|
|
CommunityEventClock: 2,
|
|
Type: protobuf.CommunityEvent_COMMUNITY_EDIT,
|
|
},
|
|
CommunityEvent{
|
|
CommunityEventClock: 3,
|
|
Type: protobuf.CommunityEvent_COMMUNITY_REQUEST_TO_JOIN_ACCEPT,
|
|
MemberToAction: "A",
|
|
},
|
|
CommunityEvent{
|
|
CommunityEventClock: 4,
|
|
Type: protobuf.CommunityEvent_COMMUNITY_REQUEST_TO_JOIN_REJECT,
|
|
MemberToAction: "A",
|
|
},
|
|
CommunityEvent{
|
|
CommunityEventClock: 5,
|
|
Type: protobuf.CommunityEvent_COMMUNITY_REQUEST_TO_JOIN_ACCEPT,
|
|
MemberToAction: "A",
|
|
},
|
|
CommunityEvent{
|
|
CommunityEventClock: 1,
|
|
Type: protobuf.CommunityEvent_COMMUNITY_REQUEST_TO_JOIN_ACCEPT,
|
|
MemberToAction: "B",
|
|
},
|
|
},
|
|
}
|
|
|
|
processor.retainNewestEventsPerEventTypeID()
|
|
s.Require().Len(processor.eventsToApply, 4)
|
|
|
|
processor.sortEvents()
|
|
|
|
s.Require().Equal(protobuf.CommunityEvent_COMMUNITY_REQUEST_TO_JOIN_ACCEPT, processor.eventsToApply[0].Type)
|
|
s.Require().EqualValues(1, processor.eventsToApply[0].CommunityEventClock)
|
|
|
|
s.Require().Equal(protobuf.CommunityEvent_COMMUNITY_EDIT, processor.eventsToApply[1].Type)
|
|
s.Require().EqualValues(2, processor.eventsToApply[1].CommunityEventClock)
|
|
|
|
s.Require().Equal(protobuf.CommunityEvent_COMMUNITY_REQUEST_TO_JOIN_REJECT, processor.eventsToApply[2].Type)
|
|
s.Require().EqualValues(4, processor.eventsToApply[2].CommunityEventClock)
|
|
|
|
s.Require().Equal(protobuf.CommunityEvent_COMMUNITY_REQUEST_TO_JOIN_ACCEPT, processor.eventsToApply[3].Type)
|
|
s.Require().EqualValues(5, processor.eventsToApply[3].CommunityEventClock)
|
|
}
|