-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Many of our integ tests use an integer as the VMID. Some of the test suites run in parallel which risks either creating the same ID multiple times or one test tearing down another test's resources. This change makes each test's VMIDs unique Signed-off-by: Kern Walster <walster@amazon.com>
- Loading branch information
Showing
5 changed files
with
97 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"). You may | ||
// not use this file except in compliance with the License. A copy of the | ||
// License is located at | ||
// | ||
// http://aws.amazon.com/apache2.0/ | ||
// | ||
// or in the "license" file accompanying this file. This file is distributed | ||
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
// express or implied. See the License for the specific language governing | ||
// permissions and limitations under the License. | ||
|
||
package integtest | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/gofrs/uuid" | ||
) | ||
|
||
// VMIDGen generates namespaced VMIDs that are unique across different VMIDGens. | ||
// We have many tests which use a numeric ID as the VMID which could conflict with | ||
// concurrently running test. VMIDGen guarantees uniqueness across different tests. | ||
type VMIDGen struct { | ||
prefix string | ||
} | ||
|
||
// NewVMIDGen creates a new VMIDGen | ||
func NewVMIDGen() (*VMIDGen, error) { | ||
uid, err := uuid.NewV4() | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &VMIDGen{uid.String()}, nil | ||
} | ||
|
||
// VMID creates a namespaced VMID given an integer seed. | ||
// A VMIDGen will generate the same VMID multiple times given the same seed, | ||
// but two different VMIDGens will generate different ids given the same seed. | ||
func (gen *VMIDGen) VMID(seed int) string { | ||
return fmt.Sprintf("%s-%d", gen.prefix, seed) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters