Skip to content

Instantly share code, notes, and snippets.

@moio
Created April 19, 2018 08:47
Show Gist options
  • Save moio/9bdb684102b1af89db3f47ad8ab2bc62 to your computer and use it in GitHub Desktop.
Save moio/9bdb684102b1af89db3f47ad8ab2bc62 to your computer and use it in GitHub Desktop.
Script to reproduce a race condition in spacewalk's lookup_evr() function
#!/usr/bin/env ruby
# encoding: UTF-8
require 'time'
require 'pg'
def random_string(rng)
"%02x" % rng.rand(2 ** 64)
end
rng = Random.new(Time.new.to_i)
conn = PG.connect(dbname: "susemanager", user: "spacewalk", password: "spacewalk", host: "suma.tf.local")
conn.prepare("lookup_evr", "SELECT lookup_evr($1, $2, $3)")
conn.transaction do
(1..1000).each do
e = random_string(rng)
v = random_string(rng)
r = random_string(rng)
conn.exec_prepared("lookup_evr", [e,v,r])
end
puts "Committing..."
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment