Skip to content

Commit 5d336fd

Browse files
committed
Merge branch 'main' into userorgs
2 parents 47f70a9 + 50d8151 commit 5d336fd

File tree

7 files changed

+46
-11
lines changed

7 files changed

+46
-11
lines changed

.github/workflows/coder.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,19 @@ jobs:
149149
150150
- run: go install gotest.tools/gotestsum@latest
151151

152-
- run:
152+
- name: Test with Mock Database
153+
run:
153154
gotestsum --jsonfile="gotests.json" --packages="./..." --
154155
-covermode=atomic -coverprofile="gotests.coverage" -timeout=3m
155156
-count=3 -race -parallel=2
156157

158+
- name: Test with PostgreSQL Database
159+
if: runner.os == 'Linux'
160+
run:
161+
DB=true gotestsum --jsonfile="gotests.json" --packages="./..." --
162+
-covermode=atomic -coverprofile="gotests.coverage" -timeout=3m
163+
-count=1 -race -parallel=2
164+
157165
- uses: codecov/codecov-action@v2
158166
with:
159167
token: ${{ secrets.CODECOV_TOKEN }}

coderd/coderdtest/coderdtest.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ package coderdtest
22

33
import (
44
"context"
5+
"database/sql"
56
"net/http/httptest"
67
"net/url"
8+
"os"
79
"testing"
810

911
"github.com/stretchr/testify/require"
@@ -12,7 +14,9 @@ import (
1214
"github.com/coder/coder/coderd"
1315
"github.com/coder/coder/codersdk"
1416
"github.com/coder/coder/cryptorand"
17+
"github.com/coder/coder/database"
1518
"github.com/coder/coder/database/databasefake"
19+
"github.com/coder/coder/database/postgres"
1620
)
1721

1822
// Server represents a test instance of coderd.
@@ -58,6 +62,20 @@ func (s *Server) RandomInitialUser(t *testing.T) coderd.CreateInitialUserRequest
5862
func New(t *testing.T) Server {
5963
// This can be hotswapped for a live database instance.
6064
db := databasefake.New()
65+
if os.Getenv("DB") != "" {
66+
connectionURL, close, err := postgres.Open()
67+
require.NoError(t, err)
68+
t.Cleanup(close)
69+
sqlDB, err := sql.Open("postgres", connectionURL)
70+
require.NoError(t, err)
71+
t.Cleanup(func() {
72+
_ = sqlDB.Close()
73+
})
74+
err = database.Migrate(sqlDB)
75+
require.NoError(t, err)
76+
db = database.New(sqlDB)
77+
}
78+
6179
handler := coderd.New(&coderd.Options{
6280
Logger: slogtest.Make(t, nil),
6381
Database: db,

database/query.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,14 @@ INSERT INTO
100100
email,
101101
name,
102102
login_type,
103+
revoked,
103104
hashed_password,
104105
created_at,
105106
updated_at,
106107
username
107108
)
108109
VALUES
109-
($1, $2, $3, $4, $5, $6, $7, $8) RETURNING *;
110+
($1, $2, $3, $4, false, $5, $6, $7, $8) RETURNING *;
110111

111112
-- name: UpdateAPIKeyByID :exec
112113
UPDATE

database/query.sql.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

peer/channel.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ func (c *Channel) init() {
135135

136136
c.conn.dcDisconnectListeners.Add(1)
137137
c.conn.dcFailedListeners.Add(1)
138+
c.conn.dcClosedWaitGroup.Add(1)
138139
go func() {
139140
var err error
140141
// A DataChannel can disconnect multiple times, so this needs to loop.
@@ -274,6 +275,7 @@ func (c *Channel) closeWithError(err error) error {
274275
close(c.sendMore)
275276
c.conn.dcDisconnectListeners.Sub(1)
276277
c.conn.dcFailedListeners.Sub(1)
278+
c.conn.dcClosedWaitGroup.Done()
277279

278280
if c.rwc != nil {
279281
_ = c.rwc.Close()

peer/conn.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ type Conn struct {
113113
dcDisconnectListeners atomic.Uint32
114114
dcFailedChannel chan struct{}
115115
dcFailedListeners atomic.Uint32
116+
dcClosedWaitGroup sync.WaitGroup
116117

117118
localCandidateChannel chan webrtc.ICECandidateInit
118119
localSessionDescriptionChannel chan webrtc.SessionDescription
@@ -125,11 +126,10 @@ type Conn struct {
125126
pingEchoChan *Channel
126127
pingEchoOnce sync.Once
127128
pingEchoError error
128-
129-
pingMutex sync.Mutex
130-
pingOnce sync.Once
131-
pingChan *Channel
132-
pingError error
129+
pingMutex sync.Mutex
130+
pingOnce sync.Once
131+
pingChan *Channel
132+
pingError error
133133
}
134134

135135
func (c *Conn) init() error {
@@ -502,5 +502,10 @@ func (c *Conn) CloseWithError(err error) error {
502502
// this call will return an error that isn't typed. We don't check the error because
503503
// closing an already closed connection isn't an issue for us.
504504
_ = c.rtc.Close()
505+
506+
// Waits for all DataChannels to exit before officially labeling as closed.
507+
// All logging, goroutines, and async functionality is cleaned up after this.
508+
c.dcClosedWaitGroup.Wait()
509+
505510
return err
506511
}

yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4350,9 +4350,9 @@ nanoclone@^0.2.1:
43504350
integrity sha512-wynEP02LmIbLpcYw8uBKpcfF6dmg2vcpKqxeH5UcoKEYdExslsdUA4ugFauuaeYdTB76ez6gJW8XAZ6CgkXYxA==
43514351

43524352
nanoid@^3.1.23:
4353-
version "3.1.30"
4354-
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.1.30.tgz#63f93cc548d2a113dc5dfbc63bfa09e2b9b64362"
4355-
integrity sha512-zJpuPDwOv8D2zq2WRoMe1HsfZthVewpel9CAvTfc/2mBD1uUT/agc5f7GHGWXlYkFvi1mVxe4IjvP2HNrop7nQ==
4353+
version "3.2.0"
4354+
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.2.0.tgz#62667522da6673971cca916a6d3eff3f415ff80c"
4355+
integrity sha512-fmsZYa9lpn69Ad5eDn7FMcnnSR+8R34W9qJEijxYhTbfOWzr22n1QxCMzXLK+ODyW2973V3Fux959iQoUxzUIA==
43564356

43574357
natural-compare@^1.4.0:
43584358
version "1.4.0"

0 commit comments

Comments
 (0)