OSDN Git Service

Added building blocks to test an issue where mtime of log files is earlier that syste...
authordaigo <beatles@users.sourceforge.jp>
Tue, 3 Aug 2010 12:31:52 +0000 (21:31 +0900)
committerDaigo Moriwaki <daigo@debian.org>
Tue, 3 Aug 2010 12:36:10 +0000 (21:36 +0900)
changelog
sample/check_file.rb [new file with mode: 0644]
sample/check_time.rb [new file with mode: 0644]
sample/check_time2.rb [new file with mode: 0644]
sample/test_time.rb [new file with mode: 0644]

index 2af9b67..0a39bad 100644 (file)
--- a/changelog
+++ b/changelog
@@ -1,3 +1,10 @@
+2010-08-03  Daigo Moriwaki <daigo at debian dot org>
+
+       * [shogi-server]
+         - sample/{check_file.rb,check_time.rb,check_time2.rb,test_time.rb}
+           Added new files to test an issue where mtime of log files was
+           earlier than system time.
+
 2010-07-25  Daigo Moriwaki <daigo at debian dot org>
 
        * [shogi-server]
diff --git a/sample/check_file.rb b/sample/check_file.rb
new file mode 100644 (file)
index 0000000..d958a68
--- /dev/null
@@ -0,0 +1,21 @@
+fname = File.join("/", "tmp", "test.txt")
+if File.exist?(fname)
+  File.rename(fname, fname+".rename")
+end
+
+10000.times do 
+  time = Time.now
+  File.new(fname, File::CREAT)
+  mtime = File.stat(fname).mtime
+  if mtime.to_i < time.to_i
+    date = `/bin/date -R`
+    p time
+    p mtime
+    p date
+    puts "time:  %d.%d" % [time.sec,   time.usec]
+    puts "mtime: %d.%d" % [mtime.sec, mtime.usec]
+    exit 1
+  end
+  File.delete fname
+end
+
diff --git a/sample/check_time.rb b/sample/check_time.rb
new file mode 100644 (file)
index 0000000..a35c4c0
--- /dev/null
@@ -0,0 +1,8 @@
+100000.times do
+  now1=Time.now
+  now2=Time.now
+  if ((now2-now1)<0) 
+    puts "now1: %d.%d" % [now1.sec, now1.usec]
+    puts "now2: %d.%d" % [now2.sec, now1.usec]
+  end
+end
diff --git a/sample/check_time2.rb b/sample/check_time2.rb
new file mode 100644 (file)
index 0000000..5f412a3
--- /dev/null
@@ -0,0 +1,8 @@
+10000.times do
+  t1 = Time.mktime(2010,7,27)
+  t2 = Time.mktime(2010,7,26,23,59,59,0.999999)
+
+  unless (t1-t2) > 0
+    puts "WHY?"
+  end
+end
diff --git a/sample/test_time.rb b/sample/test_time.rb
new file mode 100644 (file)
index 0000000..bc566bb
--- /dev/null
@@ -0,0 +1,29 @@
+require 'time'
+
+class Time
+
+  @@offset = Time.now - Time.mktime(Time.now.year, Time.now.month, Time.now.day+1) + 10
+  class << self
+    alias :orig_now :now
+    def now
+      return orig_now - @@offset
+    end
+  end
+
+#  def initialize
+#    super
+#=begin
+#    if @@offset == 0
+#      current = Time.orig_now
+#      @@offset = current - Time.mk_time(current.year, current.month, current.day)
+#    end
+#=end
+#  end
+
+end
+
+if $0 == __FILE__
+  puts Time.now
+  sleep 1
+  puts Time.now
+end