File tree Expand file tree Collapse file tree 4 files changed +27
-6
lines changed Expand file tree Collapse file tree 4 files changed +27
-6
lines changed Original file line number Diff line number Diff line change @@ -150,9 +150,12 @@ jobs:
150150 terraform_wrapper : false
151151
152152 - name : Test with Mock Database
153+ env :
154+ GOCOUNT : ${{ runner.os == 'Windows' && 3 || 5 }}
155+ GOMAXPROCS : ${{ runner.os == 'Windows' && 1 || 2 }}
153156 run : gotestsum --junitfile="gotests.xml" --packages="./..." --
154157 -covermode=atomic -coverprofile="gotests.coverage"
155- -timeout=3m -count=5 -race -short -parallel=2
158+ -timeout=3m -count=$GOCOUNT -race -short -failfast
156159
157160 - name : Upload DataDog Trace
158161 if : (success() || failure()) && github.actor != 'dependabot[bot]'
@@ -166,10 +169,10 @@ jobs:
166169 if : runner.os == 'Linux'
167170 run : DB=true gotestsum --junitfile="gotests.xml" --packages="./..." --
168171 -covermode=atomic -coverprofile="gotests.coverage" -timeout=3m
169- -count=1 -race -parallel=2
172+ -count=1 -race -parallel=2 -failfast
170173
171174 - name : Upload DataDog Trace
172- if : (success() || failure()) && github.actor != 'dependabot[bot]'
175+ if : (success() || failure()) && github.actor != 'dependabot[bot]' && runner.os == 'Linux'
173176 env :
174177 DATADOG_API_KEY : ${{ secrets.DATADOG_API_KEY }}
175178 DD_DATABASE : postgresql
Original file line number Diff line number Diff line change 44 "context"
55 "database/sql"
66 "io"
7+ "net"
78 "net/http/httptest"
89 "net/url"
910 "os"
@@ -59,7 +60,13 @@ func New(t *testing.T) *codersdk.Client {
5960 Database : db ,
6061 Pubsub : pubsub ,
6162 })
62- srv := httptest .NewServer (handler )
63+ srv := httptest .NewUnstartedServer (handler )
64+ srv .Config .BaseContext = func (_ net.Listener ) context.Context {
65+ ctx , cancelFunc := context .WithCancel (context .Background ())
66+ t .Cleanup (cancelFunc )
67+ return ctx
68+ }
69+ srv .Start ()
6370 serverURL , err := url .Parse (srv .URL )
6471 require .NoError (t , err )
6572 t .Cleanup (srv .Close )
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ package pty
66import (
77 "io"
88 "os"
9+ "sync"
910
1011 "github.com/creack/pty"
1112)
@@ -23,6 +24,7 @@ func newPty() (PTY, error) {
2324}
2425
2526type otherPty struct {
27+ mutex sync.Mutex
2628 pty , tty * os.File
2729}
2830
@@ -41,13 +43,18 @@ func (p *otherPty) Output() io.ReadWriter {
4143}
4244
4345func (p * otherPty ) Resize (cols uint16 , rows uint16 ) error {
46+ p .mutex .Lock ()
47+ defer p .mutex .Unlock ()
4448 return pty .Setsize (p .tty , & pty.Winsize {
4549 Rows : rows ,
4650 Cols : cols ,
4751 })
4852}
4953
5054func (p * otherPty ) Close () error {
55+ p .mutex .Lock ()
56+ defer p .mutex .Unlock ()
57+
5158 err := p .pty .Close ()
5259 if err != nil {
5360 return err
Original file line number Diff line number Diff line change @@ -8,13 +8,17 @@ import (
88 "syscall"
99
1010 "github.com/creack/pty"
11+ "golang.org/x/xerrors"
1112)
1213
1314func startPty (cmd * exec.Cmd ) (PTY , error ) {
1415 ptty , tty , err := pty .Open ()
1516 if err != nil {
16- return nil , err
17+ return nil , xerrors . Errorf ( "open: %w" , err )
1718 }
19+ defer func () {
20+ _ = tty .Close ()
21+ }()
1822 cmd .SysProcAttr = & syscall.SysProcAttr {
1923 Setsid : true ,
2024 Setctty : true ,
@@ -25,7 +29,7 @@ func startPty(cmd *exec.Cmd) (PTY, error) {
2529 err = cmd .Start ()
2630 if err != nil {
2731 _ = ptty .Close ()
28- return nil , err
32+ return nil , xerrors . Errorf ( "start: %w" , err )
2933 }
3034 return & otherPty {
3135 pty : ptty ,
You can’t perform that action at this time.
0 commit comments