From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-3.0 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_MED,SPF_PASS,T_DKIM_INVALID, T_RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id EF2011FAEB for ; Sat, 10 Jun 2017 14:10:13 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 4FFBE1207E1; Sat, 10 Jun 2017 23:10:11 +0900 (JST) Received: from o1678948x4.outbound-mail.sendgrid.net (o1678948x4.outbound-mail.sendgrid.net [167.89.48.4]) by neon.ruby-lang.org (Postfix) with ESMTPS id 00FCE1207C1 for ; Sat, 10 Jun 2017 23:10:08 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=sendgrid.me; h=from:to:references:subject:mime-version:content-type:content-transfer-encoding:list-id; s=smtpapi; bh=/YwaQ/zm42hUecolqPLd1yrsp4g=; b=liBQMQR6xKXwWXc2zT 3j8FqO55UmBeVfv0kPzWdpdmLqWxeBs+7VGUZMULy0pNpT83kOmBTIpYTfrQ4GNY iECNKQxhkyc4YERelKkNDY1RLYAO67kacChIdZTKcjHPWtCdCBEImQNqI/lCe7z2 wOdIXDOpcIrQQdnZb4MO4glhk= Received: by filter0593p1mdw1.sendgrid.net with SMTP id filter0593p1mdw1-20500-593BFD88-48 2017-06-10 14:09:12.975786051 +0000 UTC Received: from herokuapp.com (ec2-184-73-50-50.compute-1.amazonaws.com [184.73.50.50]) by ismtpd0005p1iad1.sendgrid.net (SG) with ESMTP id QRLihwIBTzuckf5DMHND2g Sat, 10 Jun 2017 14:09:12.950 +0000 (UTC) Date: Sat, 10 Jun 2017 14:09:12 +0000 From: Greg.mpls@gmail.com To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 56674 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 13644 X-Redmine-Issue-Author: MSP-Greg X-Redmine-Sender: MSP-Greg X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: ync6xU2WACa70kv/Ymy4QrNMhiuLXJG8OTL2vJD1yS4I0kxLEGOHg+Lr55HWwWfkrA8FubwmsAfb1p zErUqSOtOOT5oFjnud8+U56UPNzN74yiP5pIc9T6q7lTwD3PMqIAwdd6Gmz8OWRKhtoDngKzwKkuCB VjcdW40J9vODrxkPhoeEJFraSN8gmIosfXkLcKZ183EGpKY4W/KRt0SfpQ== X-ML-Name: ruby-core X-Mail-Count: 81648 Subject: [ruby-core:81648] [Ruby trunk Bug#13644] Windows - Setting Time.now X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #13644 has been updated by MSP-Greg (Greg L). Nobuyoshi, > It's defined in FakeTime module which is prepended to Time. Thank you for being so polite and taking the time to respond. That was a very dumb mistake on my part. I reached that conclusion when I was fighting a poor, old, MinGW embedded ruby 2.2.4 build in a commercial app. It was nice when I swapped in my build of 2.3 stable, and everything worked... Anyway, I believe I've found the real issue. It may be occurring because I'm using Win7, or possibly because I have UAC enabled. On my system, File.utime only sets atime, not mtime. I suspect that the OS may not allow setting mtime. As you probably know, `LogDevice.new` uses mtime to determine whether it's time to create a new log file. Normally, I can't see how that would be an issue, but re this test trying to mock things, it is. If you have a minute, could you check the following code? For a MinGW build, it changes LogDevice to use atime to determine whether to create a new log. ```ruby require 'logger' module PLogDevice def initialize(log = nil, shift_age: nil, shift_size: nil, shift_period_suffix: nil) @dev = @filename = @shift_age = @shift_size = @shift_period_suffix = nil mon_initialize set_dev(log) if @filename @shift_age = shift_age || 7 @shift_size = shift_size || 1048576 @shift_period_suffix = shift_period_suffix || '%Y%m%d' unless @shift_age.is_a?(Integer) base_time = @dev.respond_to?(:stat) ? (RUBY_PLATFORM !~ /mingw/ ? @dev.stat.mtime : @dev.stat.atime) : # @dev.stat.mtime : Time.now @next_rotate_time = next_rotate_time(base_time, @shift_age) end end end end class Logger::LogDevice ; prepend PLogDevice ; end module FakeTime ; attr_accessor :now ; end class << Time ; prepend FakeTime ; end log = "log" File.open(log, "w") {} File.utime(*[Time.mktime(2014, 1, 2, 0, 0, 0)]*2, log) Time.now = Time.mktime(2014, 1, 2, 23, 59, 59, 999000) dev = Logger::LogDevice.new(log, shift_age: 'daily') dev.write("#{Time.now} hello-1\n") dev.close puts "\nTime.now #{Time.now}\n" \ "atime #{File.atime(log)}\n" \ "mtime #{File.mtime(log)}\n" Time.now = Time.mktime(2014, 1, 3, 1, 1, 1) dev = Logger::LogDevice.new(log, shift_age: 'daily') dev.write("#{Time.now} hello-2\n") dev.close puts "\nTime.now #{Time.now}\n" \ "atime #{File.atime(log)}\n" \ "mtime #{File.mtime(log)}\n" ``` It may show more than needed, but as listed, the logs are written correctly. If you uncomment ```ruby # @dev.stat.mtime : ``` and comment ```ruby (RUBY_PLATFORM !~ /mingw/ ? @dev.stat.mtime : @dev.stat.atime) : ``` it behaves as normal (using mtime) and will fail. Hence, I don't believe there's an issue with logger, it's an issue with trying to mock this. If adding the prepend to LogDevice looks okay, someone should do a PR or commit. Again, thanks for all your work, both Ruby in general and windows issues. ---------------------------------------- Bug #13644: Windows - Setting Time.now https://bugs.ruby-lang.org/issues/13644#change-65342 * Author: MSP-Greg (Greg L) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: ruby 2.5.0dev (2017-06-04 trunk 59013) [x64-mingw32] * Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN ---------------------------------------- While reviewing a MinGW build `test-all` failure in [TestLogDevice#test_shifting_midnight_exist_file](https://github.com/ruby/ruby/blob/trunk/test/logger/test_logdevice.rb#L687-L727), I determined the cause. The test in question (and other tests that seem to have newer/better exception handling) sets `Time.now`. The thread [StackOverflow - Change system date programmatically](https://stackoverflow.com/questions/650849/change-system-date-programmatically) seems to imply that in some instances/configurations, changing the system time on Windows systems requires elevated permissions. I tested on both a mswin build (`ruby 2.5.0dev (2017-05-27 trunk 58922) [x64-mswin64_140]`) and a MinGW build (`ruby 2.5.0dev (2017-06-08 trunk 59046) [x64-mingw32]`), and both responded to: ```ruby Time.now = Time.mktime(2017, 1, 3, 1, 1, 1) ``` with the following eror: ``` undefined method `now=' for Time:Class (NoMethodError) ``` Both also had `false = Time.respond_to?(:now=)`. So, I'm confused as to how this test passes on mswin. Regardless, the test requires a skip to bypass it and allow MinGW test-all to pass. I thought I'd file an issue before doing a PR. I'm building and testing on Win7. Finally, if anyone has time, where is the method `now=` defined? -- https://bugs.ruby-lang.org/