Skip to content

Commit 8a7cbea

Browse files
committed
fix: add dynamic names to endpoints in APIConnection and update Iteration ID handling
1 parent 1915b04 commit 8a7cbea

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

core/dbio/api/api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,7 @@ func (ac *APIConnection) RenderDynamicEndpoints() (err error) {
672672
g.Debug("running setup sequence (%d calls)", len(dynEndpoint.Setup))
673673

674674
baseEndpoint := &Endpoint{
675+
Name: "dynamic.setup",
675676
context: g.NewContext(ac.Context.Ctx),
676677
conn: ac,
677678
State: setupState,

core/dbio/api/api_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ func TestHTTPCallAndResponseExtraction(t *testing.T) {
707707
Env map[string]string `yaml:"env"`
708708
Err bool `yaml:"err"`
709709

710-
MockResponse any `yaml:"mock_response"` // can be map or string (for CSV)
710+
MockResponse any `yaml:"mock_response"` // can be map or string (for CSV)
711711
ExpectedRecords []map[string]any `yaml:"expected_records"`
712712
ExpectedState map[string]any `yaml:"expected_state"`
713713
ExpectedNextState map[string]any `yaml:"expected_next_state"`
@@ -970,7 +970,7 @@ func TestHTTPCallAndResponseExtraction(t *testing.T) {
970970

971971
// Create a mock single request with our response data
972972
iter := &Iteration{
973-
id: 1,
973+
id: g.F("i%02d", 1),
974974
state: endpoint.State,
975975
endpoint: endpoint,
976976
context: g.NewContext(context.Background()),

core/dbio/api/auth.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ func (ac *APIConnection) Authenticate() (err error) {
6868
case AuthTypeSequence:
6969
// create ephemeral endpoint
7070
baseEndpoint := &Endpoint{
71+
Name: "api.auth",
7172
State: g.M(),
7273
context: g.NewContext(ac.Context.Ctx),
7374
conn: ac,

core/dbio/api/spec.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,7 @@ func (ep *Endpoint) setup() (err error) {
581581
g.Debug("running endpoint setup sequence (%d calls)", len(ep.Setup))
582582

583583
baseEndpoint := &Endpoint{
584+
Name: g.F("%s.setup", ep.Name),
584585
context: g.NewContext(ep.context.Ctx),
585586
conn: ep.conn,
586587
State: g.M(),
@@ -618,6 +619,7 @@ func (ep *Endpoint) teardown() (err error) {
618619
g.Debug("running endpoint teardown sequence (%d calls)", len(ep.Teardown))
619620

620621
baseEndpoint := &Endpoint{
622+
Name: g.F("%s.teardown", ep.Name),
621623
context: g.NewContext(ep.context.Ctx),
622624
conn: ep.conn,
623625
State: g.M(),
@@ -721,20 +723,20 @@ type Iterate struct {
721723
}
722724

723725
type Iteration struct {
724-
state StateMap // each iteration has its own state
725-
id int // iteration ID
726-
sequence int // paginated request number
727-
field string // state field
728-
value any // state value
729-
stop bool // whether to stop the iteration
730-
context *g.Context
731-
endpoint *Endpoint
726+
state StateMap // each iteration has its own state
727+
id string // iteration ID
728+
sequence int // paginated request number
729+
field string // state field
730+
value any // state value
731+
stop bool // whether to stop the iteration
732+
context *g.Context
733+
endpoint *Endpoint
734+
requestWg sync.WaitGroup // request wait group
732735
}
733736

734737
func (iter *Iteration) Debug(text string, args ...any) {
735-
if iter.field != "" {
736-
id := g.F("i%02d", iter.id)
737-
text = env.DarkGrayString(id) + " " + text
738+
if iter.id != "" {
739+
text = env.DarkGrayString(iter.id) + " " + text
738740
}
739741
g.Debug(text, args...)
740742
}
@@ -866,7 +868,7 @@ func NewSingleRequest(iter *Iteration) *SingleRequest {
866868

867869
id := g.F("r.%04d.%s", iter.endpoint.totalReqs, g.RandString(g.AlphaRunesLower, 3))
868870
if iter.field != "" {
869-
id = g.F("i%02d.r%03d.%s", iter.id, iter.sequence, g.RandString(g.AlphaRunesLower, 3))
871+
id = g.F("%s.r%03d.%s", iter.id, iter.sequence, g.RandString(g.AlphaRunesLower, 3))
870872
}
871873

872874
return &SingleRequest{

0 commit comments

Comments
 (0)