Skip to content

Commit

Permalink
ensure one connection per VU
Browse files Browse the repository at this point in the history
  • Loading branch information
lwlee2608 committed Nov 10, 2023
1 parent 7b6a247 commit 6e7870e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
33 changes: 22 additions & 11 deletions diameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ type DiameterClient struct {
}

type DiameterMessage struct {
//header
name string // test

diamMsg *diam.Message
avps []*DiameterAVP
avps []*DiameterAVP // may need to mutex lock this
}

type DiameterAVP struct {
Expand Down Expand Up @@ -69,17 +68,9 @@ func (*Diameter) NewClient() (*DiameterClient, error) {
},
}

conn, err := client.DialNetwork("tcp", "localhost:3868")
if err != nil {
log.Errorf("Error connecting to %s, %v\n", "localhost:3868", err)
return nil, err
}

log.Infof("Connected to %s\n", "localhost:3868")

return &DiameterClient{
client: client,
conn: conn,
conn: nil,
hopIds: hopIds,
}, nil
}
Expand Down Expand Up @@ -156,8 +147,28 @@ func (a *DiameterAVP) XDiameterIdentity(value string) *DiameterAVP {

// TODO add more data type

func (c *DiameterClient) Connect(address string) error {
if c.conn != nil {
return nil
}

conn, err := c.client.DialNetwork("tcp", address)
if err != nil {
log.Errorf("Error connecting to %s, %v\n", "localhost:3868", err)
return err
}
log.Infof("Connected to %s\n", "localhost:3868")

c.conn = conn
return nil
}

func (d *Diameter) Send(client *DiameterClient, msg *DiameterMessage) (uint32, error) {

if client.conn == nil {
return 0, errors.New("Not connected")
}

req := msg.diamMsg

for _, avp := range msg.avps {
Expand Down
4 changes: 3 additions & 1 deletion example.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import { check } from 'k6';

export let options = {
iterations: 5,
vus: 1,
vus: 2,
}

let client = diameter.newClient();

export default function () {
client.connect("localhost:3868")

let msg = diameter.newMessage("CCR");
msg.addAVP().Code(263).Mbit().UTF8String("Session-8888"); // Session ID
msg.addAVP().Code(264).DiameterIdentity("origin.host") // Origin-Host
Expand Down

0 comments on commit 6e7870e

Please sign in to comment.