Created
April 19, 2018 08:47
-
-
Save moio/9bdb684102b1af89db3f47ad8ab2bc62 to your computer and use it in GitHub Desktop.
Script to reproduce a race condition in spacewalk's lookup_evr() function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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