Stop test when feeder becomes empty

I have, in my opinion, a very straightforward scenario I want to test. There are thousands of files on my server, and I’m trying to simulate a dozen users accessing files at different intervals. It is important that a file is NOT accessed twice, because I want to compare caching strategies. I simply want all of the users to pop files from a queue feeder and stop execution gracefully when there are no more files.

I can’t know in advance how many files a single user is going to access because of the random nature of the requests, so I need a different strategy. Any help is appreciated.

stop execution gracefully

The key word is “gracefully” here. A single request + loop scenario might be easy to stop gracefully: just exit the loop. But for more complex scenarios, the “gracefully” expectation might be way more complicated. As a result, that’s not something that’s built-in.

Still, you could achieve that pretty easily with an AtomicInteger:

val count = new AtomicInteger(number_of_files)

val scn = scenario(“foo”)
.asLongAs(session → count.decrementAndGet() != 0).on(

feed(your_files_feeder)
.exec(sendFile)
)