Skip to content

Commit

Permalink
fix(test): increase git daemon test timeout & close db
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed May 2, 2023
1 parent 5ec5570 commit cbc155d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
5 changes: 2 additions & 3 deletions server/daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"os"
"strings"
"testing"
"time"

"github.com/charmbracelet/soft-serve/server/backend/sqlite"
"github.com/charmbracelet/soft-serve/server/config"
Expand Down Expand Up @@ -53,6 +52,7 @@ func TestMain(m *testing.M) {
os.Unsetenv("SOFT_SERVE_GIT_IDLE_TIMEOUT")
os.Unsetenv("SOFT_SERVE_GIT_LISTEN_ADDR")
_ = d.Close()
_ = fb.Close()
os.Exit(code)
}

Expand All @@ -61,12 +61,11 @@ func TestIdleTimeout(t *testing.T) {
if err != nil {
t.Fatal(err)
}
time.Sleep(2 * time.Second)
out, err := readPktline(c)
if err != nil && !errors.Is(err, io.EOF) {
t.Fatalf("expected nil, got error: %v", err)
}
if out != ErrTimeout.Error() {
if out != ErrTimeout.Error() || out == "" {
t.Fatalf("expected %q error, got %q", ErrTimeout, out)
}
}
Expand Down
19 changes: 12 additions & 7 deletions server/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import (
func TestSession(t *testing.T) {
is := is.New(t)
t.Run("authorized repo access", func(t *testing.T) {
s := setup(t)
t.Log("setting up")
s, close := setup(t)
s.Stderr = os.Stderr
defer s.Close()
t.Log("requesting pty")
err := s.RequestPty("xterm", 80, 40, nil)
is.NoErr(err)
go func() {
Expand All @@ -32,13 +33,16 @@ func TestSession(t *testing.T) {
// FIXME: exit with code 0 instead of forcibly closing the session
s.Close()
}()
err = s.Run("test")
t.Log("waiting for session to exit")
_, err = s.Output("test")
var ee *gossh.ExitMissingError
is.True(errors.As(err, &ee))
t.Log("session exited")
_ = close()
})
}

func setup(tb testing.TB) *gossh.Session {
func setup(tb testing.TB) (*gossh.Session, func() error) {
tb.Helper()
is := is.New(tb)
dp := tb.TempDir()
Expand All @@ -60,9 +64,10 @@ func setup(tb testing.TB) *gossh.Session {
return testsession.New(tb, &ssh.Server{
Handler: bm.MiddlewareWithProgramHandler(SessionHandler(cfg), termenv.ANSI256)(func(s ssh.Session) {
_, _, active := s.Pty()
tb.Logf("PTY active %v", active)
tb.Log(s.Command())
if !active {
os.Exit(1)
}
s.Exit(0)
}),
}, nil)
}, nil), fb.Close
}

0 comments on commit cbc155d

Please sign in to comment.