Skip to content

Commit c3c0cc0

Browse files
integration test: longer counting to avoid flakiness
1 parent 8ddeeee commit c3c0cc0

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

internal/integration/server/server.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,33 +157,32 @@ func (m mutationResolver) CreateUser(ctx context.Context, input NewUser) (*User,
157157
return &newUser, nil
158158
}
159159

160-
func (s *subscriptionResolver) Count(ctx context.Context) (<-chan int, error) {
160+
func countTo(stopCount int) (<-chan int, error) {
161161
respChan := make(chan int, 1)
162162
go func(respChan chan int) {
163163
defer close(respChan)
164-
counter := 0
165-
for {
166-
if counter == 10 {
167-
return
168-
}
164+
for counter := range stopCount {
169165
respChan <- counter
170-
counter++
171166
time.Sleep(100 * time.Millisecond)
172167
}
173168
}(respChan)
174169
return respChan, nil
175170
}
176171

172+
func (s *subscriptionResolver) Count(ctx context.Context) (<-chan int, error) {
173+
return countTo(10)
174+
}
175+
177176
func (s *subscriptionResolver) CountAuthorized(ctx context.Context) (<-chan int, error) {
178177
if getAuthToken(ctx) != "authorized-user-token" {
179178
return nil, fmt.Errorf("unauthorized")
180179
}
181180

182-
return s.Count(ctx)
181+
return countTo(10)
183182
}
184183

185184
func (s *subscriptionResolver) CountClose(ctx context.Context) (<-chan int, error) {
186-
return s.Count(ctx)
185+
return countTo(1000)
187186
}
188187

189188
const AuthKey = "authToken"

0 commit comments

Comments
 (0)