-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests for the hammer analysis (#137)
Basic tests to make sure that the average reported is correct and that async behaviour is reliable. Both the test and the analysis code under test had race unsafe code, which is now fixed.
- Loading branch information
1 parent
2ff487d
commit a9fe306
Showing
3 changed files
with
88 additions
and
16 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
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,67 @@ | ||
// Copyright 2024 The Tessera authors. 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. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License 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 main | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestHammerAnalyser_Stats(t *testing.T) { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
var treeSize treeSizeState | ||
ha := newHammerAnalyser(treeSize.getSize) | ||
|
||
go ha.updateStatsLoop(ctx) | ||
|
||
time.Sleep(100 * time.Millisecond) | ||
|
||
baseTime := time.Now().Add(-1 * time.Minute) | ||
for i := 0; i < 10; i++ { | ||
ha.seqLeafChan <- leafTime{ | ||
idx: uint64(i), | ||
queuedAt: baseTime, | ||
assignedAt: baseTime.Add(time.Duration(i) * time.Second), | ||
} | ||
} | ||
treeSize.setSize(10) | ||
time.Sleep(500 * time.Millisecond) | ||
|
||
avg := ha.queueTime.Avg() | ||
if want := float64(4500); avg != want { | ||
t.Errorf("integration time avg: got != want (%f != %f)", avg, want) | ||
} | ||
} | ||
|
||
type treeSizeState struct { | ||
size uint64 | ||
mux sync.RWMutex | ||
} | ||
|
||
func (s *treeSizeState) getSize() uint64 { | ||
s.mux.RLock() | ||
defer s.mux.RUnlock() | ||
return s.size | ||
} | ||
|
||
func (s *treeSizeState) setSize(size uint64) { | ||
s.mux.Lock() | ||
defer s.mux.Unlock() | ||
s.size = size | ||
} |
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