Skip to content

Commit

Permalink
create resource asyc
Browse files Browse the repository at this point in the history
Signed-off-by: myan <[email protected]>
  • Loading branch information
yanmxa committed Jul 9, 2024
1 parent b68cc08 commit 021a1f0
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions test/integration/consumers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ func TestConsumerDeleting(t *testing.T) {
account := h.NewRandAccount()
ctx := h.NewAuthenticatedContext(account)

// create 20 consumers
consumerNum := 20
// create 30 consumers
consumerNum := 30
consumerIdToName := map[string]string{}
for i := 0; i < consumerNum; i++ {
consumerName := "tom" + fmt.Sprint(i)
Expand All @@ -230,16 +230,18 @@ func TestConsumerDeleting(t *testing.T) {
consumerIdToName[*consumer.Id] = consumerName
}

// asynchronously attaching 10 resources to each consumer
resourceNum := 10
var wg sync.WaitGroup
resourceChan := make(chan *Result, resourceNum*consumerNum)
consumerChan := make(chan *Result, consumerNum)

for id, name := range consumerIdToName {
wg.Add(1)
go func(name, id string) {
defer wg.Done()
for i := 0; i < resourceNum; i++ {
// attach resource to the consumer

var wg sync.WaitGroup
// asynchronously attaching 10 resources to each consumer
for i := 0; i < resourceNum; i++ {
wg.Add(1)
go func(name, id string) {
defer wg.Done()
res := h.NewAPIResource(name, 1)
resource, resp, err := client.DefaultApi.ApiMaestroV1ResourcesPost(ctx).Resource(res).Execute()
resourceChan <- &Result{
Expand All @@ -249,13 +251,10 @@ func TestConsumerDeleting(t *testing.T) {
consumerId: id,
err: err,
}
}
}(name, id)
}
}(name, id)
}

// delete consumer when creating resources on it
consumerChan := make(chan *Result, consumerNum)
for id, name := range consumerIdToName {
// delete the consumer when creating resources on it
wg.Add(1)
go func(name, id string) {
defer wg.Done()
Expand All @@ -267,9 +266,9 @@ func TestConsumerDeleting(t *testing.T) {
err: err,
}
}(name, id)
}

wg.Wait()
wg.Wait()
}

// verify the deleting consumer:
// 1. success -> no resources is associated with it
Expand Down

0 comments on commit 021a1f0

Please sign in to comment.