pollForLineageMappings polls the database until the expected number of lineage mappings appear
(ctx context.Context, ds database.IDataSource, balanceID string, expectedCount int, pollInterval, timeout time.Duration)
| 16 | |
| 17 | // pollForLineageMappings polls the database until the expected number of lineage mappings appear |
| 18 | func pollForLineageMappings(ctx context.Context, ds database.IDataSource, balanceID string, expectedCount int, pollInterval, timeout time.Duration) ([]model.LineageMapping, error) { |
| 19 | timeoutCtx, cancel := context.WithTimeout(ctx, timeout) |
| 20 | defer cancel() |
| 21 | |
| 22 | ticker := time.NewTicker(pollInterval) |
| 23 | defer ticker.Stop() |
| 24 | |
| 25 | for { |
| 26 | select { |
| 27 | case <-timeoutCtx.Done(): |
| 28 | return nil, fmt.Errorf("timed out waiting for %d lineage mappings for balance %s: %w", expectedCount, balanceID, timeoutCtx.Err()) |
| 29 | case <-ticker.C: |
| 30 | mappings, err := ds.GetLineageMappings(timeoutCtx, balanceID) |
| 31 | if err != nil { |
| 32 | continue |
| 33 | } |
| 34 | if len(mappings) >= expectedCount { |
| 35 | return mappings, nil |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | // pollForBalance polls until the balance reaches the expected value |
| 42 | func pollForBalance(ctx context.Context, ds database.IDataSource, balanceID string, expectedBalance *big.Int, pollInterval, timeout time.Duration) (*model.Balance, error) { |
no test coverage detected