From afaa377e877515c31a941b4c88953e20ead17255 Mon Sep 17 00:00:00 2001 From: matthias Date: Thu, 15 Aug 2019 17:33:26 +0200 Subject: add simple test for data race detection --- contrib/gofpdi/gofpdi_test.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'contrib/gofpdi') diff --git a/contrib/gofpdi/gofpdi_test.go b/contrib/gofpdi/gofpdi_test.go index 1ecc5ca..77db338 100644 --- a/contrib/gofpdi/gofpdi_test.go +++ b/contrib/gofpdi/gofpdi_test.go @@ -5,6 +5,8 @@ import ( "github.com/jung-kurt/gofpdf" "github.com/jung-kurt/gofpdf/internal/example" "io" + "sync" + "testing" ) func ExampleGofpdiImporter() { @@ -39,6 +41,29 @@ func ExampleGofpdiImporter() { // Successfully generated ../../pdf/contrib_gofpdi_Importer.pdf } +func TestGofpdiConcurrent(t *testing.T) { + wg := sync.WaitGroup{} + for i := 0; i < 100; i++ { + wg.Add(1) + go func() { + defer wg.Done() + pdf := gofpdf.New("P", "mm", "A4", "") + rs, _ := getTemplatePdf() + imp := NewImporter() + tpl := imp.ImportPageFromStream(pdf, &rs, 1, "/MediaBox") + pdf.AddPage() + tpl = imp.ImportPageFromStream(pdf, &rs, 1, "/MediaBox") + imp.UseImportedTemplate(pdf, tpl, 0, 0, 210.0, 297.0) + // write to bytes buffer + buf := bytes.Buffer{} + if err := pdf.Output(&buf); err != nil { + t.Fail() + } + }() + } + wg.Wait() +} + func getTemplatePdf() (io.ReadSeeker, error) { tpdf := gofpdf.New("P", "pt", "A4", "") tpdf.AddPage() -- cgit v1.2.1-24-ge1ad