|
| 1 | +// Copyright 2025 The go-ethereum Authors |
| 2 | +// This file is part of the go-ethereum library. |
| 3 | +// |
| 4 | +// The go-ethereum library is free software: you can redistribute it and/or modify |
| 5 | +// it under the terms of the GNU Lesser General Public License as published by |
| 6 | +// the Free Software Foundation, either version 3 of the License, or |
| 7 | +// (at your option) any later version. |
| 8 | +// |
| 9 | +// The go-ethereum library is distributed in the hope that it will be useful, |
| 10 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +// GNU Lesser General Public License for more details. |
| 13 | +// |
| 14 | +// You should have received a copy of the GNU Lesser General Public License |
| 15 | +// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +package common |
| 18 | + |
| 19 | +import ( |
| 20 | + "testing" |
| 21 | + "time" |
| 22 | +) |
| 23 | + |
| 24 | +func TestCalculateETA(t *testing.T) { |
| 25 | + type args struct { |
| 26 | + done uint64 |
| 27 | + left uint64 |
| 28 | + elapsed time.Duration |
| 29 | + } |
| 30 | + tests := []struct { |
| 31 | + name string |
| 32 | + args args |
| 33 | + want time.Duration |
| 34 | + }{ |
| 35 | + { |
| 36 | + name: "zero done", |
| 37 | + args: args{done: 0, left: 100, elapsed: time.Second}, |
| 38 | + want: 0, |
| 39 | + }, |
| 40 | + { |
| 41 | + name: "zero elapsed", |
| 42 | + args: args{done: 1, left: 100, elapsed: 0}, |
| 43 | + want: 0, |
| 44 | + }, |
| 45 | + { |
| 46 | + name: "@Jolly23 's case", |
| 47 | + args: args{done: 16858580, left: 41802252, elapsed: 66179848 * time.Millisecond}, |
| 48 | + want: 164098440 * time.Millisecond, |
| 49 | + // wrong msg: msg="Indexing state history" processed=16858580 left=41802252 elapsed=18h22m59.848s eta=11h36m42.252s |
| 50 | + // should be around 45.58 hours |
| 51 | + }, |
| 52 | + } |
| 53 | + for _, tt := range tests { |
| 54 | + t.Run(tt.name, func(t *testing.T) { |
| 55 | + if got := CalculateETA(tt.args.done, tt.args.left, tt.args.elapsed); got != tt.want { |
| 56 | + t.Errorf("CalculateETA() = %v ms, want %v ms", got.Milliseconds(), tt.want) |
| 57 | + } |
| 58 | + }) |
| 59 | + } |
| 60 | +} |
0 commit comments