(t *testing.T)
| 537 | } |
| 538 | |
| 539 | func TestConcurrentThumbsGeneration(t *testing.T) { |
| 540 | t.Parallel() |
| 541 | |
| 542 | app, err := tests.NewTestApp() |
| 543 | if err != nil { |
| 544 | t.Fatal(err) |
| 545 | } |
| 546 | defer app.Cleanup() |
| 547 | |
| 548 | fsys, err := app.NewFilesystem() |
| 549 | if err != nil { |
| 550 | t.Fatal(err) |
| 551 | } |
| 552 | defer fsys.Close() |
| 553 | |
| 554 | // create a dummy file field collection |
| 555 | demo1, err := app.FindCollectionByNameOrId("demo1") |
| 556 | if err != nil { |
| 557 | t.Fatal(err) |
| 558 | } |
| 559 | fileField := demo1.Fields.GetByName("file_one").(*core.FileField) |
| 560 | fileField.Protected = false |
| 561 | fileField.MaxSelect = 1 |
| 562 | fileField.MaxSize = 999999 |
| 563 | // new thumbs |
| 564 | fileField.Thumbs = []string{"111x111", "111x222", "111x333"} |
| 565 | demo1.Fields.Add(fileField) |
| 566 | if err = app.Save(demo1); err != nil { |
| 567 | t.Fatal(err) |
| 568 | } |
| 569 | |
| 570 | fileKey := "wsmn24bux7wo113/al1h9ijdeojtsjy/300_Jsjq7RdBgA.png" |
| 571 | |
| 572 | urls := []string{ |
| 573 | "/api/files/" + fileKey + "?thumb=111x111", |
| 574 | "/api/files/" + fileKey + "?thumb=111x111", // should still result in single thumb |
| 575 | "/api/files/" + fileKey + "?thumb=111x222", |
| 576 | "/api/files/" + fileKey + "?thumb=111x333", |
| 577 | } |
| 578 | |
| 579 | var wg sync.WaitGroup |
| 580 | |
| 581 | wg.Add(len(urls)) |
| 582 | |
| 583 | for _, url := range urls { |
| 584 | go func() { |
| 585 | defer wg.Done() |
| 586 | |
| 587 | recorder := httptest.NewRecorder() |
| 588 | |
| 589 | req := httptest.NewRequest("GET", url, nil) |
| 590 | |
| 591 | pbRouter, _ := apis.NewRouter(app) |
| 592 | mux, _ := pbRouter.BuildMux() |
| 593 | if mux != nil { |
| 594 | mux.ServeHTTP(recorder, req) |
| 595 | } |
| 596 | }() |
nothing calls this directly
no test coverage detected
searching dependent graphs…