diff options
author | matthias <matthias@steuerbot.com> | 2019-08-15 17:33:26 +0200 |
---|---|---|
committer | matthias <matthias@steuerbot.com> | 2019-08-15 17:33:26 +0200 |
commit | afaa377e877515c31a941b4c88953e20ead17255 (patch) | |
tree | dbf7d7959d274468a817dee6bab94b45cb492b61 | |
parent | 03b1cc4baaf3f7c9ae441b711e18fdd5671a5dd4 (diff) |
add simple test for data race detection
-rw-r--r-- | contrib/gofpdi/gofpdi_test.go | 25 |
1 files changed, 25 insertions, 0 deletions
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() |