Permalink
Browse files

Fix bug in usage log which would cause errors after closing out a log.

Removed a whole lotta debugging puts.
Use assert_equal everywhere
Reanimating conversion_tests
Whitespace fatwa in tests
  • Loading branch information...
1 parent 290e689 commit 6d1dfedc3b02be4f7fecc975c6bb57ae867278c4 @celeduc celeduc committed Jan 17, 2012
View
@@ -1,4 +1,4 @@
-Finished tests in 550.431757s, 0.1126 tests/s, 4.0732 assertions/s.
+Finished tests in 534.317159s, 0.1273 tests/s, 4.2465 assertions/s.
1) Failure:
test_json(TestJson) [/home/ubuntu/src/simple_record/test/test_json.rb:51]:
@@ -13,72 +13,49 @@ test_single_clob(TestLobs) [/home/ubuntu/src/simple_record/test/test_lobs.rb:87]
puts is 1, should be 0.
4) Failure:
-test_big_result(TestResultsArray) [/home/ubuntu/src/simple_record/test/test_results_array.rb:27]:
-Failed assertion, no message given.
+test_big_result(TestResultsArray) [/home/ubuntu/src/simple_record/test/test_results_array.rb:31]:
+rs.size should be 110, is 109
5) Failure:
-test_limit(TestResultsArray) [/home/ubuntu/src/simple_record/test/test_results_array.rb:51]:
-Failed assertion, no message given.
+test_count(TestSimpleRecord) [/home/ubuntu/src/simple_record/test/test_simple_record.rb:291]:
+<2> expected but was
+<3>.
6) Failure:
-test_count(TestSimpleRecord) [/home/ubuntu/src/simple_record/test/test_simple_record.rb:325]:
-should have been 3 select, but was actually 2
+test_dirty(TestSimpleRecord) [/home/ubuntu/src/simple_record/test/test_simple_record.rb:205]:
+<1> expected but was
+<0>.
- 7) Failure:
-test_dirty(TestSimpleRecord) [/home/ubuntu/src/simple_record/test/test_simple_record.rb:230]:
-Failed assertion, no message given.
-
- 8) Error:
+ 7) Error:
test_explicit_class_name(TestSimpleRecord):
-SimpleRecord::RecordNotFound: Couldn't find MyModel with ID ["b6ba1d58-3de9-11e1-b3fa-080027c736d0"]
+SimpleRecord::RecordNotFound: Couldn't find MyModel with ID ["6157ffde-40e5-11e1-ba09-080027c736d0"]
/home/ubuntu/src/simple_record/lib/simple_record/translations.rb:93:in `eval'
/home/ubuntu/src/simple_record/lib/simple_record/active_sdb.rb:300:in `find_with_metadata'
- /home/ubuntu/src/simple_record/lib/simple_record.rb:964:in `find'
+ /home/ubuntu/src/simple_record/lib/simple_record.rb:967:in `find'
(eval):1:in `sdb_to_ruby'
/home/ubuntu/src/simple_record/lib/simple_record/translations.rb:93:in `eval'
/home/ubuntu/src/simple_record/lib/simple_record/translations.rb:93:in `sdb_to_ruby'
/home/ubuntu/src/simple_record/lib/simple_record/attributes.rb:397:in `get_attribute'
/home/ubuntu/src/simple_record/lib/simple_record/attributes.rb:186:in `block in belongs_to'
- /home/ubuntu/src/simple_record/test/test_simple_record.rb:586:in `test_explicit_class_name'
+ /home/ubuntu/src/simple_record/test/test_simple_record.rb:531:in `test_explicit_class_name'
+
+ 8) Failure:
+test_nil_attr_deletion(TestSimpleRecord) [/home/ubuntu/src/simple_record/test/test_simple_record.rb:359]:
+<0> expected but was
+<1>.
9) Failure:
-test_nil_attr_deletion(TestSimpleRecord) [/home/ubuntu/src/simple_record/test/test_simple_record.rb:397]:
-hmmm, not size 1: 0
+test_null(TestSimpleRecord) [/home/ubuntu/src/simple_record/test/test_simple_record.rb:384]:
+<2> expected but was
+<1>.
10) Failure:
-test_null(TestSimpleRecord) [/home/ubuntu/src/simple_record/test/test_simple_record.rb:422]:
-Failed assertion, no message given.
-
- 11) Failure:
test_save_get(TestSimpleRecord) [/home/ubuntu/src/simple_record/test/test_simple_record.rb:33]:
Failed assertion, no message given.
- 12) Error:
+ 11) Error:
test_storage_format(TestSimpleRecord):
NoMethodError: undefined method `[]' for nil:NilClass
- /home/ubuntu/src/simple_record/test/test_simple_record.rb:599:in `test_storage_format'
-
- 13) Error:
-test_more_validations(TestValidations):
-IOError: closed stream
- /home/ubuntu/src/simple_record/lib/simple_record/logging.rb:23:in `write'
- /home/ubuntu/src/simple_record/lib/simple_record/logging.rb:23:in `puts'
- /home/ubuntu/src/simple_record/lib/simple_record/logging.rb:23:in `write_usage'
- /home/ubuntu/src/simple_record/lib/simple_record.rb:966:in `find'
- /home/ubuntu/src/simple_record/lib/simple_record.rb:815:in `delete_all'
- /home/ubuntu/src/simple_record/test/test_validations.rb:62:in `test_more_validations'
-
- 14) Error:
-test_validations(TestValidations):
-IOError: closed stream
- /home/ubuntu/src/simple_record/lib/simple_record/logging.rb:23:in `write'
- /home/ubuntu/src/simple_record/lib/simple_record/logging.rb:23:in `puts'
- /home/ubuntu/src/simple_record/lib/simple_record/logging.rb:23:in `write_usage'
- /home/ubuntu/src/simple_record/lib/simple_record.rb:966:in `find'
- /home/ubuntu/src/simple_record/lib/simple_record/validations.rb:74:in `block in validate_uniques'
- /home/ubuntu/src/simple_record/lib/simple_record/validations.rb:70:in `each_pair'
- /home/ubuntu/src/simple_record/lib/simple_record/validations.rb:70:in `validate_uniques'
- /home/ubuntu/src/simple_record/lib/simple_record/validations.rb:45:in `valid?'
- /home/ubuntu/src/simple_record/test/test_validations.rb:31:in `test_validations'
+ /home/ubuntu/src/simple_record/test/test_simple_record.rb:543:in `test_storage_format'
-62 tests, 2242 assertions, 10 failures, 4 errors, 0 skips
+68 tests, 2269 assertions, 9 failures, 2 errors, 0 skips
View
@@ -98,6 +98,9 @@ def log_usage(types={})
def close_usage_log(type)
return unless @usage_logging_options[type]
@usage_logging_options[type][:file].close if @usage_logging_options[type][:file]
+ # unless we remove it, it will keep trying to log these events
+ # and will fail because the file is closed.
+ @usage_logging_options.delete(type)
end
def usage_logging_options
View
@@ -1,44 +0,0 @@
-require "yaml"
-require 'aws'
-
-require_relative "test_base"
-require_relative "../lib/simple_record"
-require_relative 'my_model'
-require_relative 'my_child_model'
-
-class ConversionsTest < TestBase
-
- def test_ints
- x = 0
- puts SimpleRecord::Translations.pad_and_offset(x)
- assert_equal "09223372036854775808", SimpleRecord::Translations.pad_and_offset(x)
-
- x = 1
- puts SimpleRecord::Translations.pad_and_offset(x)
- assert_equal "09223372036854775809", SimpleRecord::Translations.pad_and_offset(x)
-
- x = "09223372036854775838"
- puts SimpleRecord::Translations.un_offset_int(x)
- assert_equal 30, SimpleRecord::Translations.un_offset_int(x)
- end
-
- # All from examples here: http://tools.ietf.org/html/draft-wood-ldapext-float-00
- def test_floats
- zero = "3 000 0.0000000000000000"
- assert_equal zero, SimpleRecord::Translations.pad_and_offset(0.0)
-
- puts 'induced = ' + "3.25e5".to_f.to_s
-
- assert_equal "5 005 3.2500000000000000", SimpleRecord::Translations.pad_and_offset("3.25e5".to_f)
- assert_equal "4 994 8.4000000000000000", SimpleRecord::Translations.pad_and_offset("8.4e-5".to_f)
- assert_equal "4 992 8.4000000000000000", SimpleRecord::Translations.pad_and_offset("8.4e-7".to_f)
- assert_equal "3 000 0.0000000000000000", SimpleRecord::Translations.pad_and_offset("0.0e0".to_f)
- assert_equal "2 004 5.7500000000000000", SimpleRecord::Translations.pad_and_offset("-4.25e-4".to_f)
- assert_equal "2 004 3.6500000000000000", SimpleRecord::Translations.pad_and_offset("-6.35e-4".to_f)
- assert_equal "2 003 3.6500000000000000", SimpleRecord::Translations.pad_and_offset("-6.35e-3".to_f)
- assert_equal "1 895 6.0000000000000000", SimpleRecord::Translations.pad_and_offset("-4.0e105".to_f)
- assert_equal "1 894 6.0000000000000000", SimpleRecord::Translations.pad_and_offset("-4.0e105".to_f)
- assert_equal "1 894 4.0000000000000000", SimpleRecord::Translations.pad_and_offset("-6.0e105".to_f)
-
- end
-end
View
@@ -35,56 +35,43 @@ class MyModel < MyBaseModel
after_update :after_update
def set_nickname
- puts 'before_create set nickname'
@attr_before_create = true
self.nickname = name if self.nickname.blank?
end
def before_save
- puts 'before_save'
@attr_before_save = true
end
def after_create
- puts 'after_create'
@attr_after_create = true
end
def after_save
- puts "after_save"
@attr_after_save = true
bump_save_count
end
def after_update
- puts "after_update"
@attr_after_update = true
end
def bump_save_count
- puts 'after_save bump save_count=' + save_count.to_s
if save_count.nil?
self.save_count = 1
else
self.save_count += 1
end
-# puts 'save_count=' + self.save_count.to_s
end
def validate
- puts 'MyModel.validate'
errors.add("name", "can't be empty.") if name.blank?
-# errors.add("nickname", "can't be empty.") if nickname.blank?
end
def validate_on_create
- puts 'MyModel.validate_on_create'
errors.add("save_count", "should be zero.") if !save_count.blank? && save_count > 0
end
def validate_on_update
- puts 'MyModel.validate_on_update'
-# puts 'save_count = ' + save_count.to_s
-# errors.add("save_count", "should not be zero.") if save_count.blank? || save_count == 0
end
def atts
@@ -16,7 +16,6 @@ def self.my_shards
def my_mapping_function
shard_num = SimpleRecord::Sharding::Hashing.sdbm_hash(self.id) % self.class.num_shards
- puts "shard_num=" + shard_num.inspect
shard_num
end
View
@@ -1,15 +0,0 @@
-
-require File.expand_path(File.dirname(__FILE__) + "/../lib/results_array")
-
-array = SimpleRecord::ResultsArray.new()
-#array.extend(ResultsArray)
-
-500.times do |i|
- array << "_ob_" + i.to_s
-end
-
-array.each do |v|
- puts v.to_s
-end
-
-puts array[10]
View
@@ -1,63 +0,0 @@
-# rubymine won't run 1.9 tests
-
-require 'minitest/unit'
-require File.expand_path(File.dirname(__FILE__) + "/../lib/simple_record")
-require "yaml"
-require 'aws'
-require 'my_model'
-require 'my_child_model'
-
-
-def setup
- @config = YAML::load(File.read('test-config.yml'))
- puts 'akey=' + @config['amazon']['access_key']
- puts 'skey=' + @config['amazon']['secret_key']
- SimpleRecord.establish_connection(@config['amazon']['access_key'], @config['amazon']['secret_key'], :port=>80, :protocol=>"http")
- SimpleRecord::Base.set_domain_prefix("simplerecord_tests_")
-end
-
-def teardown
- SimpleRecord.close_connection()
-end
-
-def test_dates
- mm = MyModel.new
- mm.name = "Travis"
- mm.age = 32
- mm.cool = true
- mm.created = DateTime.now - 10
- mm.updated = DateTime.now
- mm.birthday = Time.now - (3600 * 24 * 365 * 10)
- puts 'before save=' + mm.inspect
- mm.save
- puts 'after save=' + mm.inspect
-
- mms = MyModel.find(:all, :conditions => ["created > ?", DateTime.now - 1])
- puts 'mms=' + mms.inspect
-
-end
-
-def test_date_comparisons
-
- t = SimpleRecord::Base.pad_and_offset(Time.now)
- puts t
- dt = SimpleRecord::Base.pad_and_offset(DateTime.now)
- puts dt
- dt_tomorrow = SimpleRecord::Base.pad_and_offset(DateTime.now + 1)
-
-
- puts 'compare=' + (t <=> dt).to_s
- puts 'compare=' + (t <=> dt_tomorrow).to_s
-
- dts = DateTime.parse(dt_tomorrow)
- puts dts.to_s
- ts = Time.parse(dt)
- puts ts.to_s
-end
-
-setup
-
-#test_dates
- test_date_comparisons
-
-teardown
View
@@ -21,20 +21,14 @@ def teardown
end
def delete_all(clz)
- puts 'delete_all ' + clz.name
obs = clz.find(:all)
obs.each do |o|
o.delete
end
-# @@sdb.select("select * from #{domain}") do |o|
-# o.delete
-# end
end
def reset_connection(options={})
- puts 'reset_connection'
@config = YAML::load(File.open(File.expand_path("~/.test_configs/simple_record.yml")))
- #puts 'inspecting config = ' + @config.inspect
SimpleRecord.enable_logging
View
@@ -0,0 +1,25 @@
+require "yaml"
+require 'aws'
+
+require_relative "test_base"
+require_relative "../lib/simple_record"
+require_relative 'models/my_model'
+require_relative 'models/my_child_model'
+
+class ConversionsTest < TestBase
+
+ def test_ints
+ x = 0
+ assert_equal "09223372036854775808", SimpleRecord::Translations.pad_and_offset(x)
+
+ x = 1
+ assert_equal "09223372036854775809", SimpleRecord::Translations.pad_and_offset(x)
+
+ x = "09223372036854775838"
+ assert_equal 30, SimpleRecord::Translations.un_offset_int(x)
+ end
+
+ def test_float
+ assert_equal 0.0, SimpleRecord::Translations.pad_and_offset("0.0".to_f)
+ end
+end
View
@@ -37,7 +37,6 @@ def test_same_value_are_not_dirty
assert !@person.name_changed?
@person.age = 70
- puts 'age_change2=' + @person.age_change.inspect
assert !@person.changed?
assert !@person.age_changed?
end
@@ -56,7 +55,6 @@ def test_reverted_changes_are_not_dirty
assert @person.age_changed?
@person.age = 70
- puts 'age_change2=' + @person.age_change.inspect
assert !@person.changed?
assert !@person.age_changed?
end
@@ -70,7 +68,6 @@ def test_storing_int_as_string
sleep 2
@person.i_as_s = 5
- puts 'i_as_s_changed=' + @person.i_as_s_change.inspect
# Maybe this should fail? What do we expect this behavior to be?
# assert !@person.changed?
# assert !@person.i_as_s_changed?
@@ -27,11 +27,10 @@ def test_domain_prefix
sleep 1
sdb_atts = @@sdb.select("select * from someprefix_people")
- puts 'sdb_atts=' + sdb_atts.inspect
@@sdb.delete_domain("someprefix_people") # doing it here so it's done before assertions might fail
- assert sdb_atts[:items].size == 1, "hmmm, not size 1: " + sdb_atts[:items].size.to_s
+ assert_equal sdb_atts[:items].size, 1
end
@@ -42,8 +41,6 @@ def test_created_col_and_updated_col
sleep 1
sdb_atts = @@sdb.select("select * from simplerecord_tests_people")
- puts 'sdb_atts=' + sdb_atts.inspect
-
@@sdb.delete_domain("simplerecord_tests_people")
Oops, something went wrong.

0 comments on commit 6d1dfed

Please sign in to comment.