Skip to content

A platform for community discussion. Free, open, simple.

DEV: Add a watched-words/mini_racer perf regression spec (#26341)

Jarek Radosz0aec53ee9b9a
diff --git a/spec/lib/pretty_text_spec.rb b/spec/lib/pretty_text_spec.rb
index fef6b44ba4e..ff4b2533aa4 100644
--- a/spec/lib/pretty_text_spec.rb
+++ b/spec/lib/pretty_text_spec.rb
@@ -1954,6 +1954,39 @@ HTML
describe "watched words - replace & link" do
after { Discourse.redis.flushdb }
+ # Makes sure that mini_racer/libv8-node env doesn't regress
+ it "finishes in a timely matter" do
+ sql = 1500.times.map { |i| <<~SQL }.join
+ INSERT INTO watched_words
+ (created_at, updated_at, word, action, replacement)
+ VALUES
+ (
+ :now,
+ :now,
+ 'word_#{i}',
+ :action,
+ 'replacement_#{i}'
+ );
+ SQL
+
+ DB.exec(sql, now: Time.current, action: WatchedWord.actions[:replace])
+
+ Fabricate(
+ :watched_word,
+ action: WatchedWord.actions[:replace],
+ word: "nope",
+ replacement: "yep",
+ )
+
+ # Due to a bug in node 18.16 and lower this takes about 11s.
+ # On node 18.19 and newer it takes about 250ms
+ expect do
+ Timeout.timeout(3) do
+ expect(PrettyText.cook("abc nope def")).to match_html("<p>abc yep def</p>")
+ end
+ end.not_to raise_error
+ end
+
it "replaces words with other words" do
Fabricate(
:watched_word,