Skip to content

Commit

Permalink
Merge pull request #337 from piggynl/test-timeout-multiplier
Browse files Browse the repository at this point in the history
extra_test.go: Add test timeout multiplier environment variable
  • Loading branch information
yuin authored May 30, 2023
2 parents 2ce4086 + b1ef69a commit 4536092
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions extra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package goldmark_test

import (
"bytes"
"os"
"strconv"
"strings"
"testing"
"time"
Expand All @@ -13,6 +15,15 @@ import (
"github.com/yuin/goldmark/testutil"
)

var testTimeoutMultiplier = 1.0

func init() {
m, err := strconv.ParseFloat(os.Getenv("GOLDMARK_TEST_TIMEOUT_MULTIPLIER"), 64)
if err == nil {
testTimeoutMultiplier = m
}
}

func TestExtras(t *testing.T) {
markdown := New(WithRendererOptions(
html.WithXHTML(),
Expand Down Expand Up @@ -108,8 +119,8 @@ func TestDeepNestedLabelPerformance(t *testing.T) {
var b bytes.Buffer
_ = markdown.Convert(source, &b)
finished := nowMillis()
if (finished - started) > 5000 {
t.Error("Parsing deep nested labels took more 5 secs")
if (finished - started) > int64(5000*testTimeoutMultiplier) {
t.Error("Parsing deep nested labels took too long")
}
}

Expand All @@ -128,8 +139,8 @@ func TestManyProcessingInstructionPerformance(t *testing.T) {
var b bytes.Buffer
_ = markdown.Convert(source, &b)
finished := nowMillis()
if (finished - started) > 5000 {
t.Error("Parsing processing instructions took more 5 secs")
if (finished - started) > int64(5000*testTimeoutMultiplier) {
t.Error("Parsing processing instructions took too long")
}
}

Expand All @@ -148,8 +159,8 @@ func TestManyCDATAPerformance(t *testing.T) {
var b bytes.Buffer
_ = markdown.Convert(source, &b)
finished := nowMillis()
if (finished - started) > 5000 {
t.Error("Parsing processing instructions took more 5 secs")
if (finished - started) > int64(5000*testTimeoutMultiplier) {
t.Error("Parsing processing instructions took too long")
}
}

Expand All @@ -168,8 +179,8 @@ func TestManyDeclPerformance(t *testing.T) {
var b bytes.Buffer
_ = markdown.Convert(source, &b)
finished := nowMillis()
if (finished - started) > 5000 {
t.Error("Parsing processing instructions took more 5 secs")
if (finished - started) > int64(5000*testTimeoutMultiplier) {
t.Error("Parsing processing instructions took too long")
}
}

Expand All @@ -188,7 +199,7 @@ func TestManyCommentPerformance(t *testing.T) {
var b bytes.Buffer
_ = markdown.Convert(source, &b)
finished := nowMillis()
if (finished - started) > 5000 {
t.Error("Parsing processing instructions took more 5 secs")
if (finished - started) > int64(5000*testTimeoutMultiplier) {
t.Error("Parsing processing instructions took too long")
}
}

0 comments on commit 4536092

Please sign in to comment.