Merge pull request #3710 from jsternberg/dap-tests-race-condition
dap: fix the race condition in the dap unit tests
This commit is contained in:
+1
-2
@@ -1,7 +1,6 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net"
|
||||
"os"
|
||||
@@ -75,7 +74,7 @@ type adapterProtocolDebugger struct {
|
||||
}
|
||||
|
||||
func (d *adapterProtocolDebugger) Start(printer *progress.Printer, opts *BuildOptions) error {
|
||||
cfg, err := d.Adapter.Start(context.Background(), d.conn)
|
||||
cfg, err := d.Adapter.Start(d.conn)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "debug adapter did not start")
|
||||
}
|
||||
|
||||
+3
-3
@@ -67,10 +67,10 @@ func New[C LaunchConfig]() *Adapter[C] {
|
||||
return d
|
||||
}
|
||||
|
||||
func (d *Adapter[C]) Start(ctx context.Context, conn Conn) (C, error) {
|
||||
d.eg, _ = errgroup.WithContext(ctx)
|
||||
func (d *Adapter[C]) Start(conn Conn) (C, error) {
|
||||
d.eg, _ = errgroup.WithContext(context.Background())
|
||||
d.eg.Go(func() error {
|
||||
return d.srv.Serve(ctx, conn)
|
||||
return d.srv.Serve(conn)
|
||||
})
|
||||
|
||||
<-d.initialized
|
||||
|
||||
+7
-7
@@ -24,7 +24,7 @@ func TestLaunch(t *testing.T) {
|
||||
|
||||
eg, _ := errgroup.WithContext(ctx)
|
||||
eg.Go(func() error {
|
||||
_, err := adapter.Start(ctx, conn)
|
||||
_, err := adapter.Start(conn)
|
||||
assert.NoError(t, err)
|
||||
return nil
|
||||
})
|
||||
@@ -57,13 +57,13 @@ func TestLaunch(t *testing.T) {
|
||||
// We should have received the initialized event.
|
||||
select {
|
||||
case <-initialized:
|
||||
default:
|
||||
case <-ctx.Done():
|
||||
assert.Fail(t, "did not receive initialized event")
|
||||
}
|
||||
|
||||
select {
|
||||
case <-configurationDone:
|
||||
case <-time.After(10 * time.Second):
|
||||
case <-ctx.Done():
|
||||
assert.Fail(t, "did not receive configurationDone response")
|
||||
}
|
||||
return nil
|
||||
@@ -82,7 +82,7 @@ func TestSetBreakpoints(t *testing.T) {
|
||||
|
||||
eg, _ := errgroup.WithContext(ctx)
|
||||
eg.Go(func() error {
|
||||
_, err := adapter.Start(ctx, conn)
|
||||
_, err := adapter.Start(conn)
|
||||
assert.NoError(t, err)
|
||||
return nil
|
||||
})
|
||||
@@ -118,7 +118,7 @@ func TestSetBreakpoints(t *testing.T) {
|
||||
// We should have received the initialized event.
|
||||
select {
|
||||
case <-initialized:
|
||||
default:
|
||||
case <-ctx.Done():
|
||||
assert.Fail(t, "did not receive initialized event")
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ func TestSetBreakpoints(t *testing.T) {
|
||||
assert.True(t, setBreakpointsResp.Success)
|
||||
assert.Len(t, setBreakpointsResp.Body.Breakpoints, 0)
|
||||
assert.NotNil(t, setBreakpointsResp.Body.Breakpoints, "breakpoints should be an empty array instead of null in the JSON")
|
||||
case <-time.After(10 * time.Second):
|
||||
case <-ctx.Done():
|
||||
assert.Fail(t, "did not receive setBreakpoints response")
|
||||
}
|
||||
return nil
|
||||
@@ -249,11 +249,11 @@ func NewTestAdapter[C LaunchConfig](t *testing.T) (*Adapter[C], Conn, *daptest.C
|
||||
t.Cleanup(func() { clientConn.Close() })
|
||||
|
||||
adapter := New[C]()
|
||||
t.Cleanup(func() { adapter.Stop() })
|
||||
|
||||
client := daptest.NewClient(clientConn)
|
||||
t.Cleanup(func() { client.Close() })
|
||||
|
||||
t.Cleanup(func() { adapter.Stop() })
|
||||
return adapter, srvConn, client
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -33,11 +33,11 @@ func NewServer(h Handler) *Server {
|
||||
return &Server{h: h}
|
||||
}
|
||||
|
||||
func (s *Server) Serve(ctx context.Context, conn Conn) error {
|
||||
func (s *Server) Serve(conn Conn) error {
|
||||
writeCh := make(chan dap.Message)
|
||||
s.ch = writeCh
|
||||
|
||||
s.ctx, s.cancel = context.WithCancelCause(ctx)
|
||||
s.ctx, s.cancel = context.WithCancelCause(context.Background())
|
||||
|
||||
// Start an error group to handle server-initiated tasks.
|
||||
s.eg, _ = errgroup.WithContext(s.ctx)
|
||||
|
||||
Reference in New Issue
Block a user