-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test: Unique concurent transaction ids
Signed-off-by: Emanuel Pargov <[email protected]>
- Loading branch information
Showing
1 changed file
with
33 additions
and
0 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 |
---|---|---|
|
@@ -24,6 +24,7 @@ package hedera | |
*/ | ||
|
||
import ( | ||
"sync" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
@@ -69,3 +70,35 @@ func TestUnitTransactionIDFromStringTrimmedZeroes(t *testing.T) { | |
require.NoError(t, err) | ||
require.Equal(t, txID.String(), "[email protected]") | ||
} | ||
|
||
func TestUnitConcurrentTransactionIDsAreUnique(t *testing.T) { | ||
const numOfTxns = 100000 | ||
|
||
account := AccountID{Account: 1} | ||
|
||
// Channel to collect generated transaction IDs | ||
idsCh := make(chan TransactionID, numOfTxns) | ||
|
||
var wg sync.WaitGroup | ||
for i := 0; i < numOfTxns; i++ { | ||
wg.Add(1) | ||
go func() { | ||
defer wg.Done() | ||
idsCh <- TransactionIDGenerate(account) | ||
}() | ||
} | ||
|
||
// Close idsCh after all goroutines complete | ||
go func() { | ||
wg.Wait() | ||
close(idsCh) | ||
}() | ||
|
||
seen := make(map[TransactionID]bool) | ||
for id := range idsCh { | ||
require.False(t, seen[id], "Transaction ID %v is not unique", id) | ||
seen[id] = true | ||
} | ||
|
||
require.Equal(t, len(seen), numOfTxns) | ||
} |