Skip to content

Commit

Permalink
test: fix race condition in testserver. (#1882)
Browse files Browse the repository at this point in the history
## What this PR does / why we need it:

Fix race condition detected in tests detected in CI.
This read
https://github.com/terramate-io/terramate/blob/main/cloud/testserver/stacks.go#L297
races against orgs upserted at
https://github.com/terramate-io/terramate/blob/main/cloud/testserver/cloudstore/store.go#L307

## Which issue(s) this PR fixes:
none

## Special notes for your reviewer:

This only affects our test infrastructure.

## Does this PR introduce a user-facing change?
```
no
```
  • Loading branch information
i4ki authored Sep 24, 2024
2 parents 8228356 + 2754bfa commit 72a754f
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion cloud/testserver/cloudstore/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ package cloudstore

import (
"encoding/json"
"maps"
"os"
"slices"
"sort"
"strconv"
"sync"
Expand Down Expand Up @@ -215,7 +217,7 @@ func (d *Data) GetOrg(uuid cloud.UUID) (Org, bool) {
defer d.mu.RUnlock()
for _, org := range d.Orgs {
if org.UUID == uuid {
return org, true
return org.Clone(), true
}
}
return Org{}, false
Expand Down Expand Up @@ -676,3 +678,17 @@ func (d *Data) getPreview(org Org, rrNumber int, pushedAt int64) (Preview, int64
}
return Preview{}, 0, false
}

// Clone the organization.
func (org Org) Clone() Org {
neworg := org // copy the non-pointer values

// clones below are all shallow clones but enough for the mutation cases we handle.
neworg.Deployments = maps.Clone(org.Deployments)
neworg.Drifts = slices.Clone(org.Drifts)
neworg.Stacks = slices.Clone(org.Stacks)
neworg.Members = slices.Clone(org.Members)
neworg.ReviewRequests = slices.Clone(org.ReviewRequests)
neworg.Previews = slices.Clone(org.Previews)
return neworg
}

0 comments on commit 72a754f

Please sign in to comment.