Skip to content

Commit

Permalink
apiclient: allow not waiting for election creation
Browse files Browse the repository at this point in the history
Signed-off-by: p4u <[email protected]>
  • Loading branch information
p4u committed Feb 16, 2024
1 parent 1a43746 commit 0b79233
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
14 changes: 8 additions & 6 deletions apiclient/election.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ func (c *HTTPclient) NewElectionRaw(process *models.Process) (types.HexBytes, er
}

// NewElection creates a new election given the election details
// and returns the ElectionID
func (c *HTTPclient) NewElection(description *api.ElectionDescription) (types.HexBytes, error) {
// and returns the ElectionID. If wait is true, it will wait until the election is created.
func (c *HTTPclient) NewElection(description *api.ElectionDescription, wait bool) (types.HexBytes, error) {
if c.account == nil {
return nil, fmt.Errorf("no account configured")
}
Expand Down Expand Up @@ -250,10 +250,12 @@ func (c *HTTPclient) NewElection(description *api.ElectionDescription) (types.He
if electionCreate.MetadataURL == "" {
log.Warnf("metadata could not be published")
}
ctx, cancel := context.WithTimeout(context.Background(), time.Second*40)
defer cancel()
if _, err := c.WaitUntilElectionCreated(ctx, electionCreate.ElectionID); err != nil {
return nil, err
if wait {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*40)
defer cancel()
if _, err := c.WaitUntilElectionCreated(ctx, electionCreate.ElectionID); err != nil {
return nil, err
}
}

return electionCreate.ElectionID, nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ func electionHandler(cli *VocdoniCLI) error {
}

infoPrint.Printf("creating new election...\n")
electionID, err := cli.api.NewElection(&description)
electionID, err := cli.api.NewElection(&description, true)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/end2endtest/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ func (t *e2eElection) setupElection(ed *vapi.ElectionDescription, nvAccts int, w
return err
}

electionID, err := t.api.NewElection(ed)
electionID, err := t.api.NewElection(ed, true)
if err != nil {
return err
}
Expand Down

0 comments on commit 0b79233

Please sign in to comment.