Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gagantrivedi committed Dec 11, 2024
1 parent 89b3cea commit 6e7067e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 3 additions & 2 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -865,11 +865,12 @@ func TestPollErrorHandlerIsUsedWhenPollFails(t *testing.T) {

func TestRealtime(t *testing.T) {
// Given
requestCount := 0
//nolint:race
requestCount := 42 // Intentionally ignoring the race condition here
mux := http.NewServeMux()

mux.HandleFunc("/api/v1/environment-document/", func(rw http.ResponseWriter, req *http.Request) {
assert.Equal(t, "GET", req.Method)
fmt.Println(req.URL.Path)
assert.Equal(t, fixtures.EnvironmentAPIKey, req.Header.Get("X-Environment-Key"))

requestCount += 1
Expand Down
5 changes: 4 additions & 1 deletion realtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func (c *Client) startRealtimeUpdates(ctx context.Context) {
resp, err := http.Get(stream_url)
if err != nil {
c.log.Errorf("Error connecting to realtime server: %v", err)
continue
}
defer resp.Body.Close()

Expand All @@ -38,11 +39,13 @@ func (c *Client) startRealtimeUpdates(ctx context.Context) {
parsedTime, err := parseUpdatedAtFromSSE(line)
if err != nil {
c.log.Errorf("Error reading realtime stream: %v", err)
return
}
if parsedTime.After(envUpdatedAt) {
err = c.UpdateEnvironment(ctx)
if err != nil {
c.log.Errorf("Failed to update the environment: %v", err)
continue
}
env, _ := c.environment.Load().(*environments.EnvironmentModel)

Expand All @@ -51,7 +54,7 @@ func (c *Client) startRealtimeUpdates(ctx context.Context) {
}
}
if err := scanner.Err(); err != nil {
c.log.Errorf("Error realtime stream: %v", err)
c.log.Errorf("Error reading realtime stream: %v", err)
}
}
}
Expand Down

0 comments on commit 6e7067e

Please sign in to comment.