Skip to content

Commit

Permalink
added nhooyr websockets
Browse files Browse the repository at this point in the history
overall better websocket connection
  • Loading branch information
ElecTwix committed Feb 17, 2024
1 parent 7c2584a commit cfbd799
Show file tree
Hide file tree
Showing 4 changed files with 372 additions and 8 deletions.
31 changes: 23 additions & 8 deletions db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/stretchr/testify/suite"
"github.com/surrealdb/surrealdb.go"
"github.com/surrealdb/surrealdb.go/pkg/conn/gorilla"
"github.com/surrealdb/surrealdb.go/pkg/conn/nhooyr"
"github.com/surrealdb/surrealdb.go/pkg/constants"

"github.com/surrealdb/surrealdb.go/pkg/conn"
Expand Down Expand Up @@ -56,17 +57,31 @@ func TestSurrealDBSuite(t *testing.T) {
SurrealDBSuite := new(SurrealDBTestSuite)
SurrealDBSuite.connImplementations = make(map[string]conn.Connection)

// // Gorilla
// Without options
buff := bytes.NewBufferString("")
logData := createLogger(t, buff)
SurrealDBSuite.connImplementations["gorilla"] = gorilla.Create().Logger(logData)
SurrealDBSuite.logBuffer = buff
gbuff := bytes.NewBufferString("")
glogData := createLogger(t, gbuff)
SurrealDBSuite.connImplementations["gorilla"] = gorilla.Create().Logger(glogData)
SurrealDBSuite.logBuffer = gbuff

// With options
buffOpt := bytes.NewBufferString("")
logDataOpt := createLogger(t, buff)
SurrealDBSuite.connImplementations["gorilla_opt"] = gorilla.Create().SetTimeOut(time.Minute).SetCompression(true).Logger(logDataOpt)
SurrealDBSuite.logBuffer = buffOpt
gbuffOpt := bytes.NewBufferString("")
glogDataOpt := createLogger(t, gbuff)
SurrealDBSuite.connImplementations["gorilla_opt"] = gorilla.Create().SetTimeOut(time.Minute).SetCompression(true).Logger(glogDataOpt)
SurrealDBSuite.logBuffer = gbuffOpt

// // Nhooyr
// Without options
nbuff := bytes.NewBufferString("")
nlogData := createLogger(t, gbuff)
SurrealDBSuite.connImplementations["nhooyr"] = nhooyr.Create().Logger(nlogData)
SurrealDBSuite.logBuffer = nbuff

// With options
nbuffOpt := bytes.NewBufferString("")
nlogDataOpt := createLogger(t, gbuff)
SurrealDBSuite.connImplementations["nhooyr_opt"] = nhooyr.Create().Logger(nlogDataOpt)
SurrealDBSuite.logBuffer = nbuffOpt

RunWsMap(t, SurrealDBSuite)
}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.20
require (
github.com/gorilla/websocket v1.5.0
github.com/stretchr/testify v1.8.4
nhooyr.io/websocket v1.8.10
)

require (
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntN
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
nhooyr.io/websocket v1.8.10 h1:mv4p+MnGrLDcPlBoWsvPP7XCzTYMXP9F9eIGoKbgx7Q=
nhooyr.io/websocket v1.8.10/go.mod h1:rN9OFWIUwuxg4fR5tELlYC04bXYowCP9GX47ivo2l+c=
Loading

0 comments on commit cfbd799

Please sign in to comment.