Skip to content

Commit

Permalink
remove setting reporters in TestWsDataHandling
Browse files Browse the repository at this point in the history
  • Loading branch information
Intizar-T committed Aug 23, 2024
1 parent 7e372ef commit cc0789d
Showing 1 changed file with 61 additions and 61 deletions.
122 changes: 61 additions & 61 deletions node/pkg/reporter/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ package reporter
import (
"context"
"testing"
"time"

"bisonai.com/miko/node/pkg/common/keys"
"bisonai.com/miko/node/pkg/dal/hub"
"bisonai.com/miko/node/pkg/db"
)

func TestFetchConfigs(t *testing.T) {
Expand All @@ -23,72 +28,67 @@ func TestRunApp(t *testing.T) {
}
}

// func TestWsDataHandling(t *testing.T) {
// ctx := context.Background()

// app := New()
func TestWsDataHandling(t *testing.T) {
ctx := context.Background()

// err := app.setReporters(ctx)
// if err != nil {
// t.Fatalf("error setting reporters: %v", err)
// }
app := New()

// conn, tmpConfig, configs, err := mockDalWsServer(ctx)
// if err != nil {
// t.Fatalf("error mocking dal ws server: %v", err)
// }
conn, tmpConfig, configs, err := mockDalWsServer(ctx)
if err != nil {
t.Fatalf("error mocking dal ws server: %v", err)
}

// app.WsHelper = conn
// go app.WsHelper.Run(ctx, app.HandleWsMessage)
// time.Sleep(100 * time.Millisecond)
app.WsHelper = conn
go app.WsHelper.Run(ctx, app.HandleWsMessage)
time.Sleep(100 * time.Millisecond)

// err = conn.Write(ctx, hub.Subscription{
// Method: "SUBSCRIBE",
// Params: []string{"submission@test-aggregate"},
// })
// if err != nil {
// t.Fatalf("error subscribing to websocket: %v", err)
// }
err = conn.Write(ctx, hub.Subscription{
Method: "SUBSCRIBE",
Params: []string{"submission@test-aggregate"},
})
if err != nil {
t.Fatalf("error subscribing to websocket: %v", err)
}

// sampleSubmissionData, err := generateSampleSubmissionData(
// tmpConfig.ID,
// int64(15),
// time.Now(),
// 1,
// "test-aggregate",
// )
// if err != nil {
// t.Fatalf("error generating sample submission data: %v", err)
// }
sampleSubmissionData, err := generateSampleSubmissionData(
tmpConfig.ID,
int64(15),
time.Now(),
1,
"test-aggregate",
)
if err != nil {
t.Fatalf("error generating sample submission data: %v", err)
}

// err = db.Publish(ctx, keys.SubmissionDataStreamKey(sampleSubmissionData.GlobalAggregate.ConfigID), sampleSubmissionData)
// if err != nil {
// t.Fatalf("error publishing sample submission data: %v", err)
// }
err = db.Publish(ctx, keys.SubmissionDataStreamKey(sampleSubmissionData.GlobalAggregate.ConfigID), sampleSubmissionData)
if err != nil {
t.Fatalf("error publishing sample submission data: %v", err)
}

// ticker := time.NewTicker(1 * time.Second)
// defer ticker.Stop()
// timeout := time.After(10 * time.Second)
// submissionDataCount := 0
ticker := time.NewTicker(1 * time.Second)
defer ticker.Stop()
timeout := time.After(10 * time.Second)
submissionDataCount := 0

// for {
// select {
// case <-ticker.C:
// if app.WsHelper != nil && app.WsHelper.IsRunning {
// submissionDataCount = 0
// for _, config := range configs {
// if _, ok := app.LatestDataMap.Load(config.Name); ok {
// submissionDataCount++
// }
// }
// if submissionDataCount == len(configs) {
// return
// }
// }
// case <-timeout:
// if submissionDataCount != len(configs) {
// t.Fatal("not all submission data received from websocket")
// }
// }
// }
// }
for {
select {
case <-ticker.C:
if app.WsHelper != nil && app.WsHelper.IsRunning {
submissionDataCount = 0
for _, config := range configs {
if _, ok := app.LatestDataMap.Load(config.Name); ok {
submissionDataCount++
}
}
if submissionDataCount == len(configs) {
return
}
}
case <-timeout:
if submissionDataCount != len(configs) {
t.Fatal("not all submission data received from websocket")
}
}
}
}

0 comments on commit cc0789d

Please sign in to comment.