Skip to content

Commit

Permalink
fix(tests): attempt to fix daemon idle test
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Dec 7, 2023
1 parent fcff605 commit 466c591
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
24 changes: 14 additions & 10 deletions pkg/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,21 +150,16 @@ func (d *GitDaemon) handleClient(conn net.Conn) {
d.conns.Close(c) // nolint: errcheck
}()

readc := make(chan struct{}, 1)
errc := make(chan error, 1)

s := pktline.NewScanner(c)
go func() {
if !s.Scan() {
if err := s.Err(); err != nil {
if nerr, ok := err.(net.Error); ok && nerr.Timeout() {
d.fatal(c, git.ErrTimeout)
} else {
d.logger.Debugf("git: error scanning pktline: %v", err)
d.fatal(c, git.ErrSystemMalfunction)
}
errc <- err
}
return
}
readc <- struct{}{}
errc <- nil
}()

select {
Expand All @@ -174,7 +169,16 @@ func (d *GitDaemon) handleClient(conn net.Conn) {
d.fatal(c, git.ErrTimeout)
}
return
case <-readc:
case err := <-errc:
if nerr, ok := err.(net.Error); ok && nerr.Timeout() {
d.fatal(c, git.ErrTimeout)
return

Check warning on line 175 in pkg/daemon/daemon.go

View check run for this annotation

Codecov / codecov/patch

pkg/daemon/daemon.go#L174-L175

Added lines #L174 - L175 were not covered by tests
} else if err != nil {
d.logger.Debugf("git: error scanning pktline: %v", err)
d.fatal(c, git.ErrSystemMalfunction)
return
}

Check warning on line 180 in pkg/daemon/daemon.go

View check run for this annotation

Codecov / codecov/patch

pkg/daemon/daemon.go#L177-L180

Added lines #L177 - L180 were not covered by tests

line := s.Bytes()
split := bytes.SplitN(line, []byte{' '}, 2)
if len(split) != 2 {
Expand Down
2 changes: 0 additions & 2 deletions pkg/daemon/daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ func TestMain(m *testing.M) {
}

func TestIdleTimeout(t *testing.T) {
// FIXME: flaky test, supposed to fail with timeout error (ErrTimeout)
t.Skip("flaky test")
c, err := net.Dial("tcp", testDaemon.addr)
if err != nil {
t.Fatal(err)
Expand Down

0 comments on commit 466c591

Please sign in to comment.