Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
linuskendall committed Jun 5, 2024
1 parent b51186b commit 9733398
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion internal/fetch/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func ShouldFetchSnapshot(
if localBaseSlot < remote[0].BaseSlot {
advice = AdviceFetchFull
return
} else if localBaseSlot == remote[0].BaseSlot {
} else if len(local) > 0 && localBaseSlot == remote[0].BaseSlot {
for _, l := range local[0].Files {
for _, r := range remote[0].Files {
if l.BaseSlot == 0 && r.BaseSlot == 0 {
Expand Down
12 changes: 7 additions & 5 deletions internal/fetch/fetch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestShouldFetchSnapshot(t *testing.T) {
minAge: 500,
maxAge: 10000,
minSlot: 113456,
advice: AdviceFetch,
advice: AdviceFetchFull,
},
{
name: "LowSlotNumber",
Expand All @@ -58,7 +58,7 @@ func TestShouldFetchSnapshot(t *testing.T) {
minAge: 50,
maxAge: 10000,
minSlot: 0,
advice: AdviceFetch,
advice: AdviceFetchFull,
},
{
name: "Refresh",
Expand All @@ -67,7 +67,7 @@ func TestShouldFetchSnapshot(t *testing.T) {
minAge: 500,
maxAge: 10000,
minSlot: 113456,
advice: AdviceFetch,
advice: AdviceFetchFull,
},
{
name: "NotNewEnough",
Expand Down Expand Up @@ -107,7 +107,8 @@ func fakeSnapshotInfo(slots []uint64) []*types.SnapshotInfo {
infos := make([]*types.SnapshotInfo, len(slots))
for i, slot := range slots {
infos[i] = &types.SnapshotInfo{
Slot: slot,
Slot: slot,
BaseSlot: slot,
}
}
return infos
Expand All @@ -118,7 +119,8 @@ func fakeSnapshotSources(slots []uint64) []types.SnapshotSource {
for i, slot := range slots {
infos[i] = types.SnapshotSource{
SnapshotInfo: types.SnapshotInfo{
Slot: slot,
Slot: slot,
BaseSlot: slot,
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/fetch/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (c *SidecarClient) ListSnapshots(ctx context.Context) (infos []*types.Snaps
// The returned response is guaranteed to have a valid ContentLength.
// The caller has the responsibility to close the response body even if the error is not nil.
func (c *SidecarClient) StreamSnapshot(ctx context.Context, name string) (res *http.Response, err error) {
snapURL := "http://" + c.resty.HostURL + "/v1/snapshot/" + url.PathEscape(name) // TODO: Don't hardcode scheme
snapURL := c.resty.HostURL + "/v1/snapshot/" + url.PathEscape(name) // TODO: Don't hardcode scheme
c.log.Info("Downloading snapshot", zap.String("snapshot_url", snapURL))
req, err := http.NewRequestWithContext(ctx, http.MethodGet, snapURL, nil)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions internal/integrationtest/sidecar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
func TestSidecar(t *testing.T) {
server, root := newSidecar(t, 100)
defer server.Close()
fmt.Println("Server url", server.URL)
client := fetch.NewSidecarClientWithOpts(server.URL,
fetch.SidecarClientOpts{Resty: resty.NewWithClient(server.Client())})

Expand All @@ -51,6 +52,7 @@ func TestSidecar(t *testing.T) {
[]*types.SnapshotInfo{
{
Slot: 100,
BaseSlot: 100,
Hash: solana.MustHashFromBase58("7jMmeXZSNcWPrB2RsTdeXfXrsyW5c1BfPjqoLW2X5T7V"),
TotalSize: 1,
Files: []*types.SnapshotFile{
Expand Down
6 changes: 5 additions & 1 deletion internal/integrationtest/tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func TestTracker(t *testing.T) {
{
SnapshotInfo: types.SnapshotInfo{
Slot: 103,
BaseSlot: 103,
Hash: solana.MustHashFromBase58("7w4zb1jh47zY5FPMPyRzDSmYf1CPirVP9LmTr5xWEs6X"),
Files: []*types.SnapshotFile{
{
Expand All @@ -122,6 +123,7 @@ func TestTracker(t *testing.T) {
{
SnapshotInfo: types.SnapshotInfo{
Slot: 102,
BaseSlot: 102,
Hash: solana.MustHashFromBase58("7sAawX1cAHVpfZGNtUAYKX2KPzdd1uPUZUTaLteWX4SB"),
Files: []*types.SnapshotFile{
{
Expand All @@ -138,6 +140,7 @@ func TestTracker(t *testing.T) {
{
SnapshotInfo: types.SnapshotInfo{
Slot: 101,
BaseSlot: 101,
Hash: solana.MustHashFromBase58("7oGBJ2HXGT17Fs9QNxu6RbH68z4rJxHZyc9gqhLWoFmq"),
Files: []*types.SnapshotFile{
{
Expand All @@ -154,6 +157,7 @@ func TestTracker(t *testing.T) {
{
SnapshotInfo: types.SnapshotInfo{
Slot: 100,
BaseSlot: 100,
Hash: solana.MustHashFromBase58("7jMmeXZSNcWPrB2RsTdeXfXrsyW5c1BfPjqoLW2X5T7V"),
Files: []*types.SnapshotFile{
{
Expand All @@ -172,7 +176,7 @@ func TestTracker(t *testing.T) {
}

func newTracker(db *index.DB) *httptest.Server {
handler := tracker.NewHandler(db)
handler := tracker.NewHandler(db, "http://localhost:8899", 1000)
gin.SetMode(gin.ReleaseMode)
engine := gin.New()
handler.RegisterHandlers(engine.Group("/v1"))
Expand Down
5 changes: 5 additions & 0 deletions internal/ledger/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func TestListSnapshots(t *testing.T) {
[]*types.SnapshotInfo{
{
Slot: 300,
BaseSlot: 100,
Hash: solana.MustHashFromBase58("AvFf9oS8A8U78HdjT9YG2sTTThLHJZmhaMn2g8vkWYnr"),
TotalSize: 3,
Files: []*types.SnapshotFile{
Expand Down Expand Up @@ -84,6 +85,7 @@ func TestListSnapshots(t *testing.T) {
},
{
Slot: 200,
BaseSlot: 100,
Hash: solana.MustHashFromBase58("AvFf9oS8A8U78HdjT9YG2sTTThLHJZmhaMn2g8vkWYnr"),
TotalSize: 2,
Files: []*types.SnapshotFile{
Expand All @@ -108,6 +110,7 @@ func TestListSnapshots(t *testing.T) {
},
{
Slot: 100,
BaseSlot: 100,
Hash: solana.MustHashFromBase58("AvFf9oS8A8U78HdjT9YG2sTTThLHJZmhaMn2g8vkWYnr"),
TotalSize: 1,
Files: []*types.SnapshotFile{
Expand All @@ -123,6 +126,7 @@ func TestListSnapshots(t *testing.T) {
},
{
Slot: 100,
BaseSlot: 50,
Hash: solana.MustHashFromBase58("AvFf9oS8A8U78HdjT9YG2sTTThLHJZmhaMn2g8vkWYnr"),
TotalSize: 2,
Files: []*types.SnapshotFile{
Expand All @@ -147,6 +151,7 @@ func TestListSnapshots(t *testing.T) {
},
{
Slot: 50,
BaseSlot: 50,
Hash: solana.MustHashFromBase58("AvFf9oS8A8U78HdjT9YG2sTTThLHJZmhaMn2g8vkWYnr"),
TotalSize: 1,
Files: []*types.SnapshotFile{
Expand Down

0 comments on commit 9733398

Please sign in to comment.