<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>yonkeltron &#187; Testing</title>
	<atom:link href="http://yonkeltron.com/tag/testing/feed/" rel="self" type="application/rss+xml" />
	<link>http://yonkeltron.com</link>
	<description>Temporary Exile</description>
	<lastBuildDate>Fri, 16 Jul 2010 18:45:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>The zen of backup theory</title>
		<link>http://yonkeltron.com/2010/02/11/the-zen-of-backup-theory/</link>
		<comments>http://yonkeltron.com/2010/02/11/the-zen-of-backup-theory/#comments</comments>
		<pubDate>Thu, 11 Feb 2010 17:33:42 +0000</pubDate>
		<dc:creator>Jonathan Magen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://yonkeltron.com/?p=607</guid>
		<description><![CDATA[When stuck inside due to all the snow, there is no better time to consider the topic of backup. Seriously, backup is important and the issue is fascinating.  The area of backup brings together so many topics in computing. Think about it! To do backup successfully, you must deal with data transfer, data integrity validation, ]]></description>
			<content:encoded><![CDATA[<p>When stuck inside due to all the snow, there is no better time to consider the topic of backup. Seriously, backup is important and the issue is fascinating.  The area of backup brings together so many topics in computing. Think about it! To do backup successfully, you must deal with data transfer, data integrity validation, networks, distributed systems, compression and, if you&#8217;re doing it right, cryptography. It is not just computer science however, but also workflow management and that somewhat-nebulous-yet-often-referred-to thing of systems thinking.</p>
<p>I got to thinking about the topic of backups and was curious as to the state of research as well as backup tools. A great intro to so-called &#8220;backup theory&#8221; is available on the <a href="http://en.wikipedia.org/wiki/Backup">&#8216;Backup&#8217; Wikipedia article</a> and <a href="http://www.educ.umu.se/~cobian/backuptheory.htm">others have written</a> on the subject <a href="http://www.google.com/search?q=backup%20theory">(Google will verify</a> that this is true). As it turns out, advances in storage have recently offered many new opportunities for improving the way that a given backup process might work.</p>
<p>Several distributed fault-tolerant filesystems are coming along quite nicely. Though the <a href="http://labs.google.com/papers/gfs.html">Google File System</a> and the equivalent <a href="http://hadoop.apache.org/hdfs/">HDFS</a> project which is part of <a href="http://hadoop.apache.org/">Apache&#8217;s Hadoop</a> have gotten much attention, there are other options. <a href="http://www.gluster.org/">GlusterFS</a> (follow <a href="http://twitter.com/gluster">GlusterFS on Twitter</a>, perhaps?) and <a href="http://ceph.newdream.net/">Ceph</a> are two excellent examples of Free/Open Source Software projects which offer the compelling combo of fault tolerance and distributed storage. They each employ replication and have similar architectures insofar as they abstract individual machines into &#8220;chunks&#8221; or &#8220;blocks&#8221; and manage replication automatically. One interesting difference is that while GlusterFS exports filesystems &#8220;as-is&#8221; (see the docs for an explanation), Ceph exports entire block devices.</p>
<p>So then what about the theory and goals of backup? In my opinion, backing up is not enough. Having a backup plan and executing it perfectly doesn&#8217;t mean a thing if the data can&#8217;t be recovered.  (In fact this issue relates strongly to a larger discussion of reliability. Rather than focusing exclusively on total time spent in a failure state, individuals concerned with reliability would also do well to consider how fast a system can recover from those failures. If a system can be up and running again after only 5 minutes, then that system can go down 12 times before reaching an hour of downtime. If another system takes 20 minutes to rebound from a failure, then that system can only go down 3 times!) I haven&#8217;t yet gotten to thinking about the problem of restoration following failure for anything other than plain old files. For example, I backup my personal data to servers in Philadelphia and California in addition to an external hard drive in my apartment. I make careful use of  old stand-byes like <a href="http://en.wikipedia.org/wiki/Tar_%28file_format%29">tar</a>, <a href="http://en.wikipedia.org/wiki/Gzip">gzip</a> and <a href="http://en.wikipedia.org/wiki/Rsync">rsync</a> along with a checksum utility like <a href="http://en.wikipedia.org/wiki/Md5sum">md5sum</a> or, more recently, something in the <a href="http://en.wikipedia.org/wiki/Sha1sum">SHA</a> family. Plus I use the <a href="http://git-scm.com/">git</a> revision control system for code and <a href="http://joey.kitenet.net/code/etckeeper/">etckeeper</a> for config. By backing up all of my configuration data in addition to my personal files, I make it so that I can easily return a given system to a usable state, if not restoring it perfectly. I have successfully restored systems by doing little more than a reverse rsync.</p>
<p>To be fair, I just spoke about about the few systems under my personal control which constitute a small and limited case. I back up to different locations which is good practice but my local copy is certainly not sufficient for anything industrial. If the disk breaks, I&#8217;m out of luck. Considering a larger-scale system is when GlusterFS, Ceph and others would come in handy. Obviously there are a <a href="http://amzn.com/0596102461">great</a> <a href="http://amzn.com/0596001533">many</a> <a href="http://amzn.com/0471227145">books</a> <a href="http://amzn.com/1420076396">written</a> about <a href="http://amzn.com/1430226625">this topic</a> but, for the purposes of discussion, if I were to build a platform for the reliable storage of huge amounts of data, my project would look something like this&#8230;</p>
<p>First, I would round up spare computers with room for extra disks. They machines would not need to be particularly fast or possess large amounts of memory. I&#8217;m not sure of the exact hardware requirements for either GlusterFS (<a href="http://gluster.com/community/documentation/index.php/Storage_Server_Installation_and_Configuration#Hardware_Requirements">vague wiki entry</a>) or Ceph but it&#8217;s hard to imagine that they&#8217;d require huge amounts of anything but disk space. Anyway, if my organization had old desktops or something which were being replaced then they might be perfect candidates.</p>
<p>Second comes storage. It seems that at the time of this writing, one can purchase a 1TB hard disk for around US$85. Let us assume that 20 desktop machines could be procured and each had two spare disk slots. For around US$3500 (figuring 2 US$85 disks per machine and a little more for tax+shipping, etc.) one could buy 20TB of storage. Now, it&#8217;s not quite that simple as the fault-tolerance scheme in both GlusterFS and Ceph relies on replication. Assuming the accepted replication factor of 3 (a norm adhered to by the Google File System), that would reduce the 20TB storage block by a third  leaving around 6 and two thirds terabytes of fault-tolerant storage. Filesystems of this type usually require cluster control processes which (ideally, I think) reside on dedicated machines so an extra machine or two would also be required. I got a good explanation of how metadata servers work in GFS/HDFS by reading the <a href="http://hadoop.apache.org/common/docs/current/hdfs_design.html">HDFS design document</a>, actually. Metadata servers and other control processes serve similar functions. Ceph documents are very explicit about not having a single point of failure whereas GlusterFS is not quite so adamant. I need some help figuring out if GlusterFS is as fault-tolerant in that respect.</p>
<p>For under US$4000, one could theoretically build over 6TB of fault-tolerant distributed storage (provided that spare machines are plentiful, something which shouldn&#8217;t be a problem for organizations with a semi-regular hardware replacement cycle). Now, as for the usage of that storage system for backup, it&#8217;s a different piece of the discussion. I&#8217;ve seen quite a few setups where a single-but-very-large server provides networked storage to a large number of users via something like samba or NFS. In this case, the big server is usually blessed with some complicated RAID arrangement which people put entirely too much faith in. No one ever listens that RAID is not a backup strategy. Personally, I don&#8217;t believe in hardware reliability because it seems silly to spend money trying to prevent hardware from failing when you know it&#8217;s going to break (eventually) anyway. I&#8217;m not saying that RAID isn&#8217;t useful because it *is* useful and has a place. What I am saying is that it&#8217;s not backup. So if an organization has a big network storage server then where does that get backed up to? It&#8217;s hard to backup 6 TB off site but it can (certainly) be done. However, if an organization is lucky enough to have multiple buildings then a distributed storage cluster like I described earlier would be an excellent addition to the overall backup infrastructure. Putting a few machines in different buildings and using it as a place to shadow the main file server and whatever else needs to be backed up would grant an added measure of security.</p>
<p>Snow days are a good time for thinking and my backup jobs went smoothly. However, I feel as if I have begun a track of study which might yield some good results. Granted, it&#8217;s not just about the technology (<a href="http://arxiv.org/abs/cs/0412074">humans screw things up</a>) but the ability to build reliable and fault-tolerant storage systems for massive amounts of data using only commodity hardware is a huge boon to users everywhere. This concludes my backup rant.</p>
]]></content:encoded>
			<wfw:commentRss>http://yonkeltron.com/2010/02/11/the-zen-of-backup-theory/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Getting somewhere with Scala</title>
		<link>http://yonkeltron.com/2009/07/31/getting-somewhere-with-scala/</link>
		<comments>http://yonkeltron.com/2009/07/31/getting-somewhere-with-scala/#comments</comments>
		<pubDate>Fri, 31 Jul 2009 21:47:44 +0000</pubDate>
		<dc:creator>Jonathan Magen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[emacs]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Scala]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://yonkeltron.com/?p=569</guid>
		<description><![CDATA[Ok, so when beginning with Scala, it was hard to figure certain things out. For example, what&#8217;s the best way to document my code? How should I go about testing my new programs? Which race in StarCraft best represents the ideals of Scala? Well, to prevent other people from getting stuck on these, I am ]]></description>
			<content:encoded><![CDATA[<p>Ok, so when beginning with Scala, it was hard to figure certain things out. For example, what&#8217;s the best way to document my code? How should I go about testing my new programs? Which race in StarCraft best represents the ideals of Scala? Well, to prevent other people from getting stuck on these, I am writing this post to help out.</p>
<p><strong>Writing code</strong></p>
<p>How best to write code? Are there IDEs which support or maybe even encourage Scala? Yes! Yes, there are!</p>
<ul>
<li><a href="http://www.scala-lang.org/node/91">IDE plugins (Eclipe, NetBeans, IntelliJ)</a></li>
<li><a href="http://www.scala-lang.org/node/354">Emacs</a> &#8211; and a post on how to <a href="http://scala.sygneca.com//tools/emacs">put many Scala pieces together with Emacs</a>.</li>
</ul>
<p><strong>Project management</strong></p>
<p>How best to keep track of Scala projects? Well, everyone&#8217;s got their favorite way to build stuff (Make and cousins) and those will most likely work fine. However, if you want something a little more specialized there are several tools which can help.</p>
<ul>
<li><a href="http://code.google.com/p/simple-build-tool/">Simple Build Tool (sbt)</a></li>
<li><a href="http://www.scala-lang.org/node/345">Apache Maven</a></li>
</ul>
<p><strong>Testing</strong></p>
<p>There is no one way to test Scala, and this is true of most langauges. However, Scala does include a test framework called SUnit. That being said, it&#8217;s slated for deprecation as soon as it can be replaced and removed. Also, the current thinking out there seems to be that SUnit sucks. So, you know what, kids? We aren&#8217;t going to let that bother us because there are many great frameworks out there which may be used to effectively test Scala. Since Scala compiles to Java bytecode, there shouldn&#8217;t be trouble testing Scala from Java or Java from Scala.</p>
<ul>
<li><a href="http://www.artima.com/scalatest/">ScalaTest</a></li>
<li><a href="http://code.google.com/p/specs/">Specs</a></li>
<li><a href="http://code.google.com/p/scalacheck/">ScalaCheck</a> (pseudo-clone of <a href="http://www.cs.chalmers.se/~rjmh/QuickCheck/">Haskell&#8217;s QuickCheck</a>)</li>
<li><a href="http://junit.org">JUnit</a> &#8211; Oldie-but-goodie still works well from Java or from Scala (<a href="http://junit.org/apidocs/org/junit/Assert.html">helpful list of assertions</a>)</li>
</ul>
<p><strong>Documentation</strong></p>
<p>Who doesn&#8217;t love documentation? I know that I sure do! To help satisfy my deep-seated urge to author code-centric exposition, there is scaladoc. Ever hear of javadoc? Yeah, it&#8217;s like that. <a href="http://java.sun.com/j2se/javadoc/writingdoccomments/">Read about javadoc here</a> and then check out the <a href="http://www.scala-lang.org/docu/files/tools/scaladoc.html">scaladoc manpage</a>. If, for some reason you don&#8217;t like scaladoc&#8217;s output, you&#8217;re in luck because there is an <a href="http://code.google.com/p/vscaladoc/">alternative generator called vscaladoc</a>.</p>
<p><strong>Notes</strong></p>
<p>This list is most likely incomplete and certainly not exhaustive. If someone would like me to add something, please provide the link and info in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://yonkeltron.com/2009/07/31/getting-somewhere-with-scala/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The trouble with USE</title>
		<link>http://yonkeltron.com/2009/07/15/the-trouble-with-use/</link>
		<comments>http://yonkeltron.com/2009/07/15/the-trouble-with-use/#comments</comments>
		<pubDate>Wed, 15 Jul 2009 18:25:27 +0000</pubDate>
		<dc:creator>Jonathan Magen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[F/OSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Lisp]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://yonkeltron.com/?p=553</guid>
		<description><![CDATA[Today, I was caught a little off-guard by a question regarding the USE directive in SQL. While, it stumped me, it did give me pause to think. First and foremost, it occurred to me that part of the reason that I was caught off-guard was because, in the past, I&#8217;ve been advised to stay away ]]></description>
			<content:encoded><![CDATA[<p>Today, I was caught a little off-guard by a question regarding the USE directive in SQL. While, it stumped me, it did give me pause to think. First and foremost, it occurred to me that part of the reason that I was caught off-guard was because, in the past, I&#8217;ve been advised to stay away from USE or similar directives in any language for a variety of reasons. For example, in languages like Ada, a use directive is a perfect way to completely clobber a namespace. Regarding the usage of JavaScript&#8217;s equivalent <code>with</code> operator, guru <a href="http://www.youtube.com/watch?v=hQVTIJBZook">Douglas Crockford has dire warnings</a> about actually writing programs which use it. Note, that the <code>using</code> directive from C#, is equivalent to an <code>import</code> in other languages (Python, Java) or even a <code>require</code> (Lisp, Ruby).</p>
<p>The perils of clobbering namespaces for the sake of convenience in any language are well know. Now, in some languages, a <code>use</code> directive is not always the culprit when namespaces get clobbered. Languages which also have an <code>as</code> clause can be dangerous as well because they obscure the true origin or name of a given object. </p>
<p>Part of the reason is that using USE or one of it&#8217;s friends is dangerous due to the fact that programmers risk forgetting that they used it. This kind of error is not restricted to the USE statement, however. For example, in Lisp, global variables are typically enclosed in asterisks by convention. So what, right? Well, early on in Practical Common Lisp, Peter Seibel points out that redirecting something like *standard-output* to point to another source, it would be all too easy to forget to put it back! Just like it&#8217;s easy to screw up redirection by forgetting to put it back, USE in most languages makes it quite easy to make trivial mistakes. </p>
<p>Now, I am not suggesting that these examples are directly equivalent. I am, however, making the point that, in this day and age, we are well aware of how easy it is to make careless mistakes and USE directives only make it easier. Say we have an example instance of an SQL server and there are a couple of databases in there. We want to work with two of them (called <code>panda</code> and <code>bamboo</code>) each but we&#8217;ve got quite a lot to do with one. For an example such as this, <a href="http://dev.mysql.com/doc/refman/5.0/en/use.html">databases like MySQL, provide USE</a> only to be compatible with <a href="http://en.wikipedia.org/wiki/Sybase#Products">Sybase</a> and even then only as a utility function.</p>
<p>In any case, we&#8217;re going back to the example. We&#8217;re at the prompt and we&#8217;re going to work with with our first database, panda. So to save ourselves trouble, we go forth with a <code>USE panda;</code> and then go about our business. Then, we&#8217;re ready to go ahead and delete a whole bunch of records from bamboo so we run our <code>DELETE * FROM trees;</code> and all should be well, right? WRONG! We forgot to switch to the right database by using <code>USE bamboo;</code> so now we&#8217;re in trouble. While this is a simplistic example, the world would be hard-pressed to find a competent programmer who&#8217;s never been tripped up by the most simple of errors.</p>
<p>It is for this reason that I am wary of USE and it&#8217;s friends. Unless there is a very good reason to USE USE, I suggest that programmers be very careful AS well AS when we USE AS. Together, they can be a tricky combo.</p>
]]></content:encoded>
			<wfw:commentRss>http://yonkeltron.com/2009/07/15/the-trouble-with-use/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Languages, platforms, paradigms and speed</title>
		<link>http://yonkeltron.com/2009/07/02/languages-platforms-paradigms-and-speed/</link>
		<comments>http://yonkeltron.com/2009/07/02/languages-platforms-paradigms-and-speed/#comments</comments>
		<pubDate>Fri, 03 Jul 2009 02:13:15 +0000</pubDate>
		<dc:creator>Jonathan Magen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Politics]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://yonkeltron.com/?p=545</guid>
		<description><![CDATA[Ever since the latest round of Ruby benchmarks came out and everyone got all excited, I got to thinking about the overall discussion about languages and the interpreted vs. compiled debate. To be fair, there will always be those who take a specific side for some small-but-important-to-them reason yet this has not stopped so many ]]></description>
			<content:encoded><![CDATA[<p>Ever since the <a href="http://www.infoq.com/news/2008/12/ruby-performance-shootout">latest round</a> of <a href="http://www.infoq.com/news/2009/05/performance-191-gc-compiler">Ruby benchmarks</a> came out and everyone got all excited, I got to thinking about the overall discussion about languages and the interpreted vs. compiled debate. To be fair, there will always be those who take a specific side for some small-but-important-to-them reason yet this has not stopped so many projects from bridging the gap, albeit with varying degrees of success. In many instances, it comes down to the different approaches taken by various language themselves and the payoffs they offer.</p>
<p>In my investigation, I came across some very enlightening sources of information on the overall discussion of language speed, code optimization and the tension between different paradigms. Please peruse the following:</p>
<ul>
<li><a href="http://www.youtube.com/watch?v=kKySEUrP7LA">Compiling and Optimizing Scripting Languages</a> &#8211; Google Tech Talk by one of the maintainers of <a href="http://www.phpcompiler.org/">phc</a>, the PHP compiler.</li>
<li><a href="http://www.youtube.com/watch?v=OKFeLZqLxzQ">Compiling Dynamic Languages</a> &#8211; Another Google Tech Talk focusing on optimization of Python.</li>
<li><a href="http://www.pphsg.org/cdsmith/types.html">What To Know Before Debating Type Systems</a> &#8211; From the neo-classics department, this essay by Chris Smith helped me gain a great deal of perspective with respect to type systems</li>
<li>LLVM stuff &#8211; <a href="http://www.youtube.com/watch?v=VeRaLPupGks">Google Tech Talk about LLVM 2.0</a>, tons of <a href="http://llvm.org/pubs/">LLVM-related</a> papers and presentations</li>
<li><a href="http://arxiv.org/abs/0902.2137">A formally verified compiler back-end</a> &#8211; Paper by Xavier Leroy that was too long for me to finish</li>
</ul>
<p>Something missing from this list?</p>
]]></content:encoded>
			<wfw:commentRss>http://yonkeltron.com/2009/07/02/languages-platforms-paradigms-and-speed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JSLint: Oh, what a wonderful thing</title>
		<link>http://yonkeltron.com/2009/03/15/jslint-oh-what-a-wonderful-thing/</link>
		<comments>http://yonkeltron.com/2009/03/15/jslint-oh-what-a-wonderful-thing/#comments</comments>
		<pubDate>Sun, 15 Mar 2009 16:17:37 +0000</pubDate>
		<dc:creator>Jonathan Magen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://yonkeltron.com/?p=514</guid>
		<description><![CDATA[Just discovered JSLint. It is very good, but it does hurt your feelings somewhat. I intend to use it heavily on my code from now on. Wish there was a stand-alone version, though. Still, it&#8217;s marvelous so use it often]]></description>
			<content:encoded><![CDATA[<p>Just discovered <a href="http://www.jslint.com/">JSLint</a>. It is very good, but it does hurt your feelings somewhat. I intend to use it heavily on my code from now on. Wish there was a stand-alone version, though. Still, it&#8217;s marvelous so use it often.</p>
]]></content:encoded>
			<wfw:commentRss>http://yonkeltron.com/2009/03/15/jslint-oh-what-a-wonderful-thing/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Trouble testing timestamps</title>
		<link>http://yonkeltron.com/2009/02/25/trouble-testing-timestamps/</link>
		<comments>http://yonkeltron.com/2009/02/25/trouble-testing-timestamps/#comments</comments>
		<pubDate>Wed, 25 Feb 2009 16:44:40 +0000</pubDate>
		<dc:creator>Jonathan Magen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://yonkeltron.com/?p=497</guid>
		<description><![CDATA[Since I&#8217;ve been encouraging myself to write more and better unit tests, I have encountered a troubling obstacle when writing tests to cover timestamp creation and updating. Let&#8217;s say I have a Record class which has a modification and creation timestamp. The ctime instance variable is created when a Record is instatiated and mtime is ]]></description>
			<content:encoded><![CDATA[<p>Since I&#8217;ve been encouraging myself to write more and better unit tests, I have encountered a troubling obstacle when writing tests to cover timestamp creation and updating. Let&#8217;s say I have a Record class which has a modification and creation timestamp. The ctime instance variable is created when a Record is instatiated and mtime is updated whenever the Record is updated. So, my test looks like this:</p>
<pre>def test_ctime
  record = Record.new
  assert_equal(Time.now, record.ctime)
end</pre>
<p>This failed because, believe it or not, the timers have <em>too high</em> a resolution! In fact, even evaluating (with the help of irb) <code>Time.now == Time.now</code> is false. This is evident by evaluating <code>5.times { puts Time.now.to_f }</code> and seeing how the output differs by a tiny amount with each iteration.</p>
<p>I response to this, I decided to generalize and adapt my assertion to accept a diminished resolution with a tolerance of one second. <code>assert_equal(Time.now.sec, record.ctime.to_i)</code>. This is still imprecise but it gets my point across.</p>
<p>I had resigned myself to accept this troublesome compromise until I went to write the test for mtime. My test for mtime updating looked like this:</p>
<pre>def test_mtime_update
  record = Record.new
  record.update
  assert_operator(Time.now, :&gt;, record.mtime)
end</pre>
<p>I feel like I am compromising because I can&#8217;t make accurate comparisons and can&#8217;t figure out how to do this properly. It seems impossible and I don&#8217;t feel as if I have adequate coverage because I can&#8217;t verify timestampt at all. Perhaps I am doing something obviously wrong or testing for the wrong things. To make myself feel better I added an <code>assert_instance_of(Time, record.ctime)</code> and the same thing for mtime. Still, this has given me much frustration and I can&#8217;t imagine no one else has encountered this before.</p>
<p>I&#8217;m writing this as part of a multithreaded application where timestamp resolution could be quite crucial and I see my tests failing to give me proper coverage. Help?</p>
]]></content:encoded>
			<wfw:commentRss>http://yonkeltron.com/2009/02/25/trouble-testing-timestamps/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
