Skip to content

Commit

Permalink
Fix lint and tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
jlewi committed Nov 25, 2024
1 parent c0d458a commit e31a36c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
15 changes: 5 additions & 10 deletions app/pkg/analyze/analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,15 @@ type fakeNotifier struct {
counts map[string]int
}

func (f *fakeNotifier) PostBlockEvent(blockID string) error {
func (f *fakeNotifier) PostSession(session *logspb.Session) error {
if f.counts == nil {
f.counts = make(map[string]int)
}
if _, ok := f.counts[blockID]; !ok {
f.counts[blockID] = 0
if _, ok := f.counts[session.GetContextId()]; !ok {
f.counts[session.GetContextId()] = 0

}
f.counts[blockID] += 1
f.counts[session.GetContextId()] += 1
return nil
}

Expand Down Expand Up @@ -276,7 +276,7 @@ func Test_Analyzer(t *testing.T) {
a.signalBlockDone = blockProccessed

fakeNotifier := &fakeNotifier{}
if err := a.Run(context.Background(), []string{rawDir}, fakeNotifier.PostBlockEvent); err != nil {
if err := a.Run(context.Background(), []string{rawDir}, fakeNotifier.PostSession); err != nil {
t.Fatalf("Analyze failed: %v", err)
}

Expand Down Expand Up @@ -323,11 +323,6 @@ func Test_Analyzer(t *testing.T) {
t.Errorf("Expected ExecutedBlock to be set")
}

// Check the block notifier was called twice; once after the generated block and once after the executed block
if fakeNotifier.counts[expectedBlockID] != 2 {
t.Errorf("Expected block notifier to be called twice but got %d", fakeNotifier.counts[expectedBlockID])
}

// Now append some logs to the logFile and see that they get processed
f, err := os.OpenFile(logFile, os.O_APPEND|os.O_WRONLY, 0644)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions app/pkg/analyze/session_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ func setup() (testTuple, error) {
}

// Process the log entry
func testNotifier(contextId string) error {
fmt.Printf("Received session end event for context: %v", contextId)
func testNotifier(session *logspb.Session) error {
fmt.Printf("Received session end event for context: %v", session.GetContextId())
return nil
}

Expand Down
3 changes: 0 additions & 3 deletions app/pkg/analyze/session_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ func NewSessionsManager(db *sql.DB) (*SessionsManager, error) {
// Get retrieves a session with the given contextID.
func (db *SessionsManager) Get(ctx context.Context, contextID string) (*logspb.Session, error) {
queries := db.queries
// TODO(https://github.com/jlewi/foyle/issues/345): Change logging to avoid duplicating session ID
log := logs.FromContext(ctx)
log = log.WithValues("contextId", contextID)

// Read the record
sessRow, err := queries.GetSession(ctx, contextID)
Expand Down

0 comments on commit e31a36c

Please sign in to comment.