Skip to content

Commit

Permalink
fix: wiped away some pretty important functionality, oops.
Browse files Browse the repository at this point in the history
Signed-off-by: SamMayWork <[email protected]>
  • Loading branch information
SamMayWork committed Feb 9, 2024
1 parent 0395957 commit 45fc854
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 15 deletions.
36 changes: 22 additions & 14 deletions internal/orchestrator/subscriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,23 +148,31 @@ func (or *orchestrator) GetSubscriptionEventsHistorical(ctx context.Context, sub
return nil, nil, err
}

if startSequence == -1 {
recordLimit := math.Min(float64(requestedFiltering.Limit), float64(config.GetInt(coreconfig.SubscriptionMaxHistoricalEventScanLength)))
if endSequence-int(recordLimit) > 0 {
startSequence = endSequence - int(recordLimit)
} else {
startSequence = 0
var unfilteredEvents []*core.EnrichedEvent
if startSequence == -1 && endSequence == -1 {
unfilteredEvents, _, err = or.GetEventsWithReferences(ctx, filter)
if err != nil {
return nil, nil, err
}
} else {
if startSequence == -1 {
recordLimit := math.Min(float64(requestedFiltering.Limit), float64(config.GetInt(coreconfig.SubscriptionMaxHistoricalEventScanLength)))
if endSequence-int(recordLimit) > 0 {
startSequence = endSequence - int(recordLimit)
} else {
startSequence = 0
}
}
}

if endSequence == -1 {
// This blind assertion is safe since the DB won't blow up, it'll just return nothing
endSequence = startSequence + 1000
}
if endSequence == -1 {
// This blind assertion is safe since the DB won't blow up, it'll just return nothing
endSequence = startSequence + 1000
}

unfilteredEvents, _, err := or.GetEventsWithReferencesInSequenceRange(ctx, filter, startSequence, endSequence)
if err != nil {
return nil, nil, err
unfilteredEvents, _, err = or.GetEventsWithReferencesInSequenceRange(ctx, filter, startSequence, endSequence)
if err != nil {
return nil, nil, err
}
}

filteredEvents, err := or.events.FilterHistoricalEventsOnSubscription(ctx, unfilteredEvents, subscription)
Expand Down
33 changes: 32 additions & 1 deletion internal/orchestrator/subscriptions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,6 @@ func TestGetHistoricalEventsForSubscriptionGettingHistoricalEventsThrows(t *test

baseEvents, _ := generateFakeEvents(20)


or.mdi.On("GetEventsInSequenceRange", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(baseEvents, nil, nil)
or.mem.On("EnrichEvents", mock.Anything, mock.Anything).Return([]*core.EnrichedEvent{}, nil)
or.mem.On("FilterHistoricalEventsOnSubscription", mock.Anything, mock.Anything, mock.Anything).Return(nil, fmt.Errorf("KERRR-BOOM!"))
Expand Down Expand Up @@ -582,3 +581,35 @@ func TestGetHistoricalEventsForSubscriptionStartSequenceNotProvided(t *testing.T
assert.Equal(t, 1000, len(retEvents))
}

func TestGetHistoricalEventsForSubscriptionNoStartOrEndSequence(t *testing.T) {
or := newTestOrchestrator()
defer or.cleanup(t)

fb := database.SubscriptionQueryFactory.NewFilter(context.Background())
filter := fb.And()
filter.Limit(1000)

baseEvents, enrichedEvents := generateFakeEvents(1000)

or.mdi.On("GetEvents", mock.Anything, mock.Anything, mock.Anything).Return(baseEvents, nil, nil)
or.mem.On("EnrichEvents", mock.Anything, mock.Anything).Return(enrichedEvents, nil)
or.mem.On("FilterHistoricalEventsOnSubscription", mock.Anything, mock.Anything, mock.Anything).Return(enrichedEvents, nil)

retEvents, _, err := or.GetSubscriptionEventsHistorical(context.Background(), &core.Subscription{}, filter, -1, -1)
assert.Equal(t, err, nil)
assert.Equal(t, 1000, len(retEvents))
}

func TestGetHistoricalEventsForSubscriptionNoStartOrEndSequenceFails(t *testing.T) {
or := newTestOrchestrator()
defer or.cleanup(t)

fb := database.SubscriptionQueryFactory.NewFilter(context.Background())
filter := fb.And()
filter.Limit(1000)

or.mdi.On("GetEvents", mock.Anything, mock.Anything, mock.Anything).Return(nil, nil, fmt.Errorf("boom!"))

_, _, err := or.GetSubscriptionEventsHistorical(context.Background(), &core.Subscription{}, filter, -1, -1)
assert.NotNil(t, err)
}

0 comments on commit 45fc854

Please sign in to comment.