Skip to content

Commit

Permalink
fix test, lint
Browse files Browse the repository at this point in the history
  • Loading branch information
matt2e committed Dec 9, 2024
1 parent dc9e611 commit 977900b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
11 changes: 5 additions & 6 deletions backend/controller/dal/dal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package dal
import (
"bytes"
"context"
"net/http"
"net/url"
"sync"
"testing"
"time"
Expand All @@ -13,23 +13,23 @@ import (
"golang.org/x/sync/errgroup"

"github.com/TBD54566975/ftl/backend/controller/artefacts"
"github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/timeline/v1/timelinev1connect"
"github.com/TBD54566975/ftl/backend/timeline"

dalmodel "github.com/TBD54566975/ftl/backend/controller/dal/model"
"github.com/TBD54566975/ftl/backend/controller/pubsub"
"github.com/TBD54566975/ftl/backend/controller/sql/sqltest"
"github.com/TBD54566975/ftl/backend/libdal"
"github.com/TBD54566975/ftl/internal/log"
"github.com/TBD54566975/ftl/internal/model"
"github.com/TBD54566975/ftl/internal/rpc"
"github.com/TBD54566975/ftl/internal/schema"
"github.com/TBD54566975/ftl/internal/sha256"
)

func TestDAL(t *testing.T) {
ctx := log.ContextWithNewDefaultLogger(context.Background())
timelineClient := timelinev1connect.NewTimelineServiceClient(http.DefaultClient, "http://localhost:8080")
ctx = rpc.ContextWithClient(ctx, timelineClient)
timelineEndpoint, err := url.Parse("http://localhost:8080")
assert.NoError(t, err)
ctx = timeline.ContextWithClient(ctx, timeline.NewClient(ctx, timelineEndpoint))
conn := sqltest.OpenForTesting(ctx, t)

pubSub := pubsub.New(ctx, conn, optional.None[pubsub.AsyncCallListener]())
Expand All @@ -38,7 +38,6 @@ func TestDAL(t *testing.T) {
var testContent = bytes.Repeat([]byte("sometestcontentthatislongerthanthereadbuffer"), 100)
var testSHA = sha256.Sum(testContent)

var err error
deploymentChangesCh := dal.DeploymentChanges.Subscribe(nil)
deploymentChanges := []DeploymentNotification{}
wg := errgroup.Group{}
Expand Down
10 changes: 5 additions & 5 deletions backend/timeline/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,16 +190,16 @@ func (s *service) StreamTimeline(ctx context.Context, req *connect.Request[timel

timelineReq := req.Msg.Query
// Default to last 1 day of events
var lastEventId optional.Option[int64]
var lastEventID optional.Option[int64]
for {
newQuery := timelineReq
// We always want ascending order for the underlying query.
newQuery.Order = timelinepb.GetTimelineRequest_ORDER_ASC
if _, ok := lastEventId.Get(); ok {
if _, ok := lastEventID.Get(); ok {
newQuery.Filters = append(newQuery.Filters, &timelinepb.GetTimelineRequest_Filter{
Filter: &timelinepb.GetTimelineRequest_Filter_Id{
Id: &timelinepb.GetTimelineRequest_IDFilter{
HigherThan: lastEventId.Ptr(),
HigherThan: lastEventID.Ptr(),
},
},
})
Expand All @@ -212,13 +212,13 @@ func (s *service) StreamTimeline(ctx context.Context, req *connect.Request[timel

newEvents := make([]*timelinepb.Event, 0, len(resp.Msg.Events))
for _, event := range resp.Msg.Events {
if lastEventId, ok := lastEventId.Get(); !ok || event.Id != lastEventId {
if lastEventID, ok := lastEventID.Get(); !ok || event.Id != lastEventID {
// This is not a duplicate event.
newEvents = append(newEvents, event)
}
}
if len(newEvents) > 0 {
lastEventId = optional.Some(newEvents[len(newEvents)-1].Id)
lastEventID = optional.Some(newEvents[len(newEvents)-1].Id)

if !ascending {
// Original query was for descending order, so reverse the events.
Expand Down

0 comments on commit 977900b

Please sign in to comment.