Note about channels being unserializable

This commit is contained in:
Patrick Mylund Nielsen 2012-01-29 04:04:33 +01:00
parent 106d5795c8
commit d5cd41da53
2 changed files with 15 additions and 1 deletions

4
README
View File

@ -141,7 +141,9 @@ func (c *Cache) Flush()
Deletes all items from the cache.
func (c *cache) Save(w io.Writer) error
Writes the cache's items (using Gob) to an io.Writer.
Writes the cache's items (using Gob) to an io.Writer. Returns an error if
the serialization fails, e.g. because there are unserializable objects like
channels in the cache.
func (c *cache) SaveFile(fname string) error
Saves the cache's items to the given filename, creating the file if it

View File

@ -551,6 +551,18 @@ func testFillAndSerialize(t *testing.T, tc *Cache) {
}
}
func TestSerializeUnserializable(t *testing.T) {
tc := New(0, 0)
ch := make(chan bool, 1)
ch <- true
tc.Set("chan", ch, 0)
fp := &bytes.Buffer{}
err := tc.Save(fp) // this should fail gracefully
if err.Error() != "gob NewTypeObject can't handle type: chan bool" {
t.Error("Error from Save was not gob NewTypeObject can't handle type chan bool:", err)
}
}
func BenchmarkCacheGet(b *testing.B) {
tc := New(0, 0)
tc.Set("foo", "bar", 0)