| 1407 | } |
| 1408 | |
| 1409 | func TestDiffMainWithTimeout(t *testing.T) { |
| 1410 | dmp := New() |
| 1411 | dmp.DiffTimeout = 200 * time.Millisecond |
| 1412 | |
| 1413 | a := "`Twas brillig, and the slithy toves\nDid gyre and gimble in the wabe:\nAll mimsy were the borogoves,\nAnd the mome raths outgrabe.\n" |
| 1414 | b := "I am the very model of a modern major general,\nI've information vegetable, animal, and mineral,\nI know the kings of England, and I quote the fights historical,\nFrom Marathon to Waterloo, in order categorical.\n" |
| 1415 | // Increase the text lengths by 1024 times to ensure a timeout. |
| 1416 | for x := 0; x < 13; x++ { |
| 1417 | a = a + a |
| 1418 | b = b + b |
| 1419 | } |
| 1420 | |
| 1421 | startTime := time.Now() |
| 1422 | dmp.DiffMain(a, b, true) |
| 1423 | endTime := time.Now() |
| 1424 | |
| 1425 | delta := endTime.Sub(startTime) |
| 1426 | |
| 1427 | // Test that we took at least the timeout period. |
| 1428 | assert.True(t, delta >= dmp.DiffTimeout, fmt.Sprintf("%v !>= %v", delta, dmp.DiffTimeout)) |
| 1429 | |
| 1430 | // Test that we didn't take forever (be very forgiving). Theoretically this test could fail very occasionally if the OS task swaps or locks up for a second at the wrong moment. |
| 1431 | assert.True(t, delta < (dmp.DiffTimeout*100), fmt.Sprintf("%v !< %v", delta, dmp.DiffTimeout*100)) |
| 1432 | } |
| 1433 | |
| 1434 | func TestDiffMainWithCheckLines(t *testing.T) { |
| 1435 | type TestCase struct { |