views:

1005

answers:

10

I have to write a bat script for a test scenario where the software that we are testing fails to write to file due to a disk full error. The test script must be automated, so that we can run it on overnight tests, for example. The test script must also work at different computers, so installing a software like a virtual machine wouldn't be the best solution in this case.

How can I simulate that error in a Windows environment?

+6  A: 

It might seem like a bit much, but one thing I can think of is to use a virtual machine, and set its virtual disk to just big enough to fit the OS on. Fill it with some garbage files to tip it over the edge, then run your program.

ryeguy
+10  A: 

You could try writing to a full floppy disk.

Edit:

In light of your edited question, you could set up a network share with no disk space quota and write to that. The error will then be produced regardless of the logged on user or machine.

Patrick McDonald
Or, from this century, a full USB disk. Repartition it, if needed.
gregmac
+1 for the USB-disk/stick/whatever.Who would spend hours and hours waiting for a floppy to react in 2009?
Arve Systad
Who even has floppy disks anymore? The intentions were good though, apologies for living in 1990! :)
Patrick McDonald
Floppies are outrageously expensive now that no one needs them anymore.
We ended up using the floppy disk solution because of the constraints of our testing enviroment. However, I think that there must be a more elegant solution for this problem.
Alceu Costa
The network share with no disk space quota sounds like a more elegant solution. Meanwhile, in this century who needs floppy drives to install Windows 2003 on a server with a SCSI RAID card whose driver isn't built into Windows. Us silly programmers, we should know better.
Windows programmer
+5  A: 

Create a secondary partition, fill it with junk and then run your program there.

mizipzor
Is there a way to write a script that automate the partition creation a configuration?
Alceu Costa
Alceu: many fdisk versions accept command line parameters.
DrJokepu
+2  A: 

Best thing that works on every computer (as testing is not neceessarily done on a dedicated machine) would be a ramdrive/ramdisk that could be set up on the fly.

Only found a Virtual Disk SDK so far see here that maybe could be included in your buzild process.

Different idea: maybe your testing computers could be set up to write to a shared network folder (that is full) mount as a drive?

Leonidas
+1  A: 

Create a new user accout, set a quota for it, and use runas to run your app as that user. (not exactly the same as disk full, but should have similar consequences.)

+5  A: 

Download and install TrueCrypt. You can then create a virtual partition of whatever size you want (a couple of megabytes), mount it and then fill it with a couple of documents.

Conrad
+2  A: 

The operating system will respond differently to it's system drive filling than to other drives filling and as such your application will do so too, surely? Simply filling a drive irrespective of what the physical media is used isn't going to be a accurate test.

Can't you mock the file system event for a full disk? Why would you want to wait until the disk is full? Wouldn't you want to monitor disk space periodically and warn the user when the disk is with a percentage margin of filling? Rather than wait until the disk space is terminal simply prevent your application from working until the issue is resolved, not doing so could effect any data IO and be unrecoverable!

If the test has to be a hard integration test then automating a virtual machine, deploying the application and then fill the remaining space with a recursive script is feasible.

Ed Blackburn
+4  A: 

You could setup a small ramdisk and write to that. See this page for some free ramdisk products.

M4N
+5  A: 

For Windows XP or later:

This command can get the amount of free space for the c:\ drive:

for /f "usebackq tokens=1-5" %%A in (`dir c:\ ^| find "bytes free"`) do (
    set FREE_SPACE=%%C
)

Replace c:\ with your drive, as needed.

You can then take some space away from this value so you have a little room to work with:

set /a FREE_SPACE=FREE_SPACE-1024

or however much space you want to keep free.

You can use the fsutil command to create a file to fill up the free space on the disk:

fsutil file createnew c:\spacehog.dat %FREE_SPACE%

Run your test, writing to the drive. After you write 1024 bytes or so you should run out of space.

Patrick Cuff
This is what I used, and it worked great. My XP install is a VM, so I did a snapshot before, fsutil, and executed my test.
Jared Oberhaus
+1  A: 

use a very small iscsi target

johnny