| 1 | package tq |
| 2 | |
| 3 | import ( |
| 4 | "sync" |
| 5 | "testing" |
| 6 | |
| 7 | "github.com/git-lfs/git-lfs/v3/lfsapi" |
| 8 | "github.com/git-lfs/git-lfs/v3/lfshttp" |
| 9 | "github.com/stretchr/testify/assert" |
| 10 | ) |
| 11 | |
| 12 | func TestManifestIsConfigurable(t *testing.T) { |
| 13 | cli := lfsapi.NewClient(lfshttp.NewContext(nil, nil, map[string]string{ |
| 14 | "lfs.transfer.maxretries": "3", |
| 15 | "lfs.transfer.maxretrydelay": "20", |
| 16 | "lfs.transfer.maxretrytime": "60", |
| 17 | })) |
| 18 | defer cli.Close() |
| 19 | |
| 20 | m := NewManifest(nil, cli, "", "") |
| 21 | assert.Equal(t, 3, m.MaxRetries()) |
| 22 | assert.Equal(t, 20, m.MaxRetryDelay()) |
| 23 | assert.Equal(t, 60, m.MaxRetryTime()) |
| 24 | } |
| 25 | |
| 26 | func TestManifestClampsValidValues(t *testing.T) { |
| 27 | cli := lfsapi.NewClient(lfshttp.NewContext(nil, nil, map[string]string{ |
| 28 | "lfs.transfer.maxretries": "-1", |
| 29 | "lfs.transfer.maxretrydelay": "-1", |
| 30 | "lfs.transfer.maxretrytime": "-1", |
| 31 | })) |
| 32 | defer cli.Close() |
| 33 | |
| 34 | m := NewManifest(nil, cli, "", "") |
| 35 | assert.Equal(t, 8, m.MaxRetries()) |
| 36 | assert.Equal(t, 10, m.MaxRetryDelay()) |
| 37 | assert.Equal(t, 300, m.MaxRetryTime()) |
| 38 | } |
| 39 | |
| 40 | func TestLazyManifestConcurrentUpgrade(t *testing.T) { |
| 41 | cli := lfsapi.NewClient(lfshttp.NewContext(nil, nil, nil)) |
| 42 | defer cli.Close() |
| 43 | |
| 44 | m := NewManifest(nil, cli, "", "") |
| 45 | |
| 46 | // Concurrent Upgrade calls must return the same concreteManifest |
| 47 | // instance and not race on the nil check. |
| 48 | start := make(chan struct{}) |
| 49 | results := make([]*concreteManifest, 2) |
| 50 | var wg sync.WaitGroup |
| 51 | for i := 0; i < 2; i++ { |
| 52 | wg.Add(1) |
| 53 | go func(idx int) { |
| 54 | defer wg.Done() |
| 55 | <-start |
| 56 | results[idx] = m.Upgrade() |
| 57 | }(i) |
| 58 | } |
| 59 | close(start) |
| 60 | wg.Wait() |
| 61 | |
| 62 | assert.Same(t, results[0], results[1], "concurrent Upgrade returned different instances") |
| 63 | } |
| 64 | |
| 65 | func TestManifestIgnoresNonInts(t *testing.T) { |
| 66 | cli := lfsapi.NewClient(lfshttp.NewContext(nil, nil, map[string]string{ |
| 67 | "lfs.transfer.maxretries": "not_an_int", |
| 68 | "lfs.transfer.maxretrydelay": "not_an_int", |
| 69 | "lfs.transfer.maxretrytime": "not_an_int", |
| 70 | })) |
| 71 | defer cli.Close() |
| 72 | |
| 73 | m := NewManifest(nil, cli, "", "") |
| 74 | assert.Equal(t, 8, m.MaxRetries()) |
| 75 | assert.Equal(t, 10, m.MaxRetryDelay()) |
| 76 | assert.Equal(t, 300, m.MaxRetryTime()) |
| 77 | } |