cinohub / libkml

Automatically exported from code.google.com/p/libkml
Other
0 stars 0 forks source link

NetCacheTest::TestOverflow fails #110

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. build and run libkml and tests in release mode on windows
2.
3.

What is the expected output? What do you see instead?
ASSERT_TRUE(url_data_net_cache_->Lookup(kUrl)) fails

What version of the product are you using? On what operating system?
r610

Did you run the unit test suite that comes with the project? Did all tests pass?

Please provide any additional information below.

The assert above is in the 2nd for loop which checks that all
items in the latter part of the range of urls "fetched" are all in the cache.

This fails because the RemoveOldest() uses exactly only the microtime
of the entry to decide what to remove.  This is not predictable if
more than one entry can be saved within the same microsecond.
In typical network usage this isn't a problem because no two urls
will be fetched within the same microsecond.  But, in this unit test
the network fetch is faked out and goes only to memory where
multiple items can be fetched within the same microsecond.

If removing the oldest is a key aspect to this cache then an
internal list, for example, could be used instead of these timestamps.
The head of the list is the next item to remove.  New items are
added to the end of the list _and_ to the map.

If this cache strategy is not key then the unit test could be relaxed.
Arguably an LRU scheme might make more sense: keep a count,
or sort of the least recently used item with the oldest item naturally
falling to the bottom.

Posting a bug to ponder this for a bit

Original issue reported on code.google.com by bent.hag...@gmail.com on 7 Jul 2009 at 10:53

GoogleCodeExporter commented 8 years ago
Also, adding a one second sleep within the loop that populates the cache causes
the test to pass.  I changed kUrlDataNetCacheSize down to 30, verified that
with no sleep this still fails, added the sleep and all is well.  The sleep 
merely
ensures a unique time stamp per item.

Original comment by bent.hag...@gmail.com on 7 Jul 2009 at 11:30

GoogleCodeExporter commented 8 years ago
fixed in r611

Original comment by kml.b...@gmail.com on 8 Jul 2009 at 11:14