good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
pggat
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
gfx
pggat
Commits
3cdd33de
Commit
3cdd33de
authored
1 year ago
by
Garet Halliday
Browse files
Options
Downloads
Patches
Plain Diff
spin up full gat and dial it properly
parent
7bf76255
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
test/config.go
+1
-3
1 addition, 3 deletions
test/config.go
test/runner.go
+12
-40
12 additions, 40 deletions
test/runner.go
test/tester_test.go
+87
-17
87 additions, 17 deletions
test/tester_test.go
with
100 additions
and
60 deletions
test/config.go
+
1
−
3
View file @
3cdd33de
package
test
import
(
"pggat/lib/gat/pool"
"pggat/lib/gat/pool/dialer"
)
type
Config
struct
{
Modes
map
[
string
]
pool
.
Options
Peer
dialer
.
Dialer
Modes
map
[
string
]
dialer
.
Dialer
}
This diff is collapsed.
Click to expand it.
test/runner.go
+
12
−
40
View file @
3cdd33de
...
...
@@ -8,8 +8,7 @@ import (
"pggat/lib/bouncer/bouncers/v2"
"pggat/lib/fed"
packets
"pggat/lib/fed/packets/v3.0"
"pggat/lib/gat/pool"
"pggat/lib/gat/pool/recipe"
"pggat/lib/gat/pool/dialer"
"pggat/lib/gsql"
"pggat/test/inst"
)
...
...
@@ -83,13 +82,13 @@ func (T *Runner) prepare(client *gsql.Client) []Capturer {
return
results
}
func
(
T
*
Runner
)
run
Control
(
)
([]
Capturer
,
error
)
{
control
,
_
,
err
:=
T
.
config
.
Pe
er
.
Dial
()
func
(
T
*
Runner
)
run
Mode
(
dialer
dialer
.
Dialer
)
([]
Capturer
,
error
)
{
server
,
_
,
err
:=
dial
er
.
Dial
()
if
err
!=
nil
{
return
nil
,
err
}
defer
func
()
{
_
=
control
.
Close
()
_
=
server
.
Close
()
}()
var
client
gsql
.
Client
...
...
@@ -108,7 +107,7 @@ func (T *Runner) runControl() ([]Capturer, error) {
return
nil
,
err
}
clientErr
,
serverErr
:=
bouncers
.
Bounce
(
&
client
,
control
,
p
)
clientErr
,
serverErr
:=
bouncers
.
Bounce
(
&
client
,
server
,
p
)
if
clientErr
!=
nil
{
return
nil
,
clientErr
}
...
...
@@ -120,43 +119,11 @@ func (T *Runner) runControl() ([]Capturer, error) {
return
results
,
nil
}
func
(
T
*
Runner
)
runMode
(
options
pool
.
Options
)
([]
Capturer
,
error
)
{
opts
:=
options
// allowing ps sync would mess up testing
opts
.
ParameterStatusSync
=
pool
.
ParameterStatusSyncNone
p
:=
pool
.
NewPool
(
opts
)
defer
p
.
Close
()
p
.
AddRecipe
(
"server"
,
recipe
.
NewRecipe
(
recipe
.
Options
{
Dialer
:
T
.
config
.
Peer
,
},
))
var
client
gsql
.
Client
results
:=
T
.
prepare
(
&
client
)
if
err
:=
client
.
Close
();
err
!=
nil
{
return
nil
,
err
}
if
err
:=
p
.
ServeBot
(
&
client
);
err
!=
nil
&&
!
errors
.
Is
(
err
,
io
.
EOF
)
{
return
nil
,
err
}
return
results
,
nil
}
func
(
T
*
Runner
)
Run
()
error
{
// control
expected
,
err
:=
T
.
runControl
()
if
err
!=
nil
{
return
ErrorIn
{
Name
:
"Control"
,
Err
:
err
,
}
}
var
errs
[]
error
var
expected
[]
Capturer
// modes
for
name
,
mode
:=
range
T
.
config
.
Modes
{
actual
,
err
:=
T
.
runMode
(
mode
)
...
...
@@ -168,6 +135,11 @@ func (T *Runner) Run() error {
continue
}
if
expected
==
nil
{
expected
=
actual
continue
}
if
len
(
expected
)
!=
len
(
actual
)
{
errs
=
append
(
errs
,
ErrorIn
{
Name
:
name
,
...
...
This diff is collapsed.
Click to expand it.
test/tester_test.go
+
87
−
17
View file @
3cdd33de
package
test_test
import
(
"crypto/rand"
"encoding/hex"
"fmt"
"net"
"strconv"
"testing"
"pggat/lib/auth/credentials"
"pggat/lib/bouncer/backends/v0"
"pggat/lib/bouncer/frontends/v0"
"pggat/lib/gat"
"pggat/lib/gat/pool"
"pggat/lib/gat/pool/dialer"
"pggat/lib/gat/pool/pools/session"
"pggat/lib/gat/pool/pools/transaction"
"pggat/lib/gat/pool/recipe"
"pggat/test"
"pggat/test/tests"
)
func
TestTester
(
t
*
testing
.
T
)
{
tester
:=
test
.
NewTester
(
test
.
Config
{
Modes
:
map
[
string
]
pool
.
Options
{
"transaction"
:
transaction
.
Apply
(
pool
.
Options
{}),
"session"
:
session
.
Apply
(
pool
.
Options
{
ServerResetQuery
:
"discard all"
,
}),
},
Peer
:
dialer
.
Net
{
Network
:
"tcp"
,
Address
:
"localhost:6432"
,
AcceptOptions
:
backends
.
AcceptOptions
{
Credentials
:
credentials
.
Cleartext
{
Username
:
"postgres"
,
Password
:
"password"
,
},
Database
:
"postgres"
,
control
:=
dialer
.
Net
{
Network
:
"tcp"
,
Address
:
"localhost:5432"
,
AcceptOptions
:
backends
.
AcceptOptions
{
Credentials
:
credentials
.
Cleartext
{
Username
:
"postgres"
,
Password
:
"password"
,
},
Database
:
"postgres"
,
},
}
// generate random password for testing
var
raw
[
32
]
byte
_
,
err
:=
rand
.
Read
(
raw
[
:
])
if
err
!=
nil
{
t
.
Error
(
err
)
return
}
password
:=
hex
.
EncodeToString
(
raw
[
:
])
creds
:=
credentials
.
Cleartext
{
Username
:
"runner"
,
Password
:
password
,
}
var
g
gat
.
PoolsMap
transactionPool
:=
pool
.
NewPool
(
transaction
.
Apply
(
pool
.
Options
{
Credentials
:
creds
,
}))
transactionPool
.
AddRecipe
(
"runner"
,
recipe
.
NewRecipe
(
recipe
.
Options
{
Dialer
:
control
,
}))
g
.
Add
(
"runner"
,
"transaction"
,
transactionPool
)
sessionPool
:=
pool
.
NewPool
(
session
.
Apply
(
pool
.
Options
{
Credentials
:
creds
,
ServerResetQuery
:
"discard all"
,
}))
sessionPool
.
AddRecipe
(
"runner"
,
recipe
.
NewRecipe
(
recipe
.
Options
{
Dialer
:
control
,
}))
g
.
Add
(
"runner"
,
"session"
,
sessionPool
)
listener
,
err
:=
gat
.
Listen
(
"tcp"
,
":0"
,
frontends
.
AcceptOptions
{})
if
err
!=
nil
{
t
.
Error
(
err
)
return
}
port
:=
listener
.
Listener
.
Addr
()
.
(
*
net
.
TCPAddr
)
.
Port
go
func
()
{
err
:=
gat
.
Serve
(
listener
,
&
g
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
}()
transactionDialer
:=
dialer
.
Net
{
Network
:
"tcp"
,
Address
:
":"
+
strconv
.
Itoa
(
port
),
AcceptOptions
:
backends
.
AcceptOptions
{
Credentials
:
creds
,
Database
:
"transaction"
,
},
}
sessionDialer
:=
dialer
.
Net
{
Network
:
"tcp"
,
Address
:
":"
+
strconv
.
Itoa
(
port
),
AcceptOptions
:
backends
.
AcceptOptions
{
Credentials
:
creds
,
Database
:
"session"
,
},
}
tester
:=
test
.
NewTester
(
test
.
Config
{
Modes
:
map
[
string
]
dialer
.
Dialer
{
"control"
:
control
,
"transaction"
:
transactionDialer
,
"session"
:
sessionDialer
,
},
})
if
err
:
=
tester
.
Run
(
if
err
=
tester
.
Run
(
tests
.
SimpleQuery
,
tests
.
Transaction
,
tests
.
Sync
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment