Giter Site home page Giter Site logo

Why does this test fail? about goon HOT 4 CLOSED

 avatar commented on July 20, 2024
Why does this test fail?

from goon.

Comments (4)

maddyblue avatar maddyblue commented on July 20, 2024

I've been looking at this and have learned a few things. Your test case is correctly identifying a bug. GetMulti, which is in charge of populating the result data, is correctly identifying this key as in memory (which is why it's returning 0 instead of 15, which it would if it had to go to memcache/datastore). However, instead of using the existing memory provided by goonPutGet, it is assigning over its location in the slice.

Get is a wrapper for GetMulti. I've modified your test to use v := []interface{}{goonPutGet} and call GetMulti(v). After the call, goonPutGet remains the same, but v now contains the data with a value of 15. So it's doing v[0] = <struct from memory cache> instead of populating the members of v[0] with the data from the cache.

The existing behavior has a nice speed and pointer benefit: the new v[0] points to the same data as is in the cache, which means modifying it in one place modifies it in all of them. I think that's good and expected. Doing something where we instead copy all of the data from the cached value into v[0] (and thus into goonPutGet) loses this feature. But, changing to the former behavior would mean changing the API (and drifting from the datastore API), which is worse.

So, the cache must always copy its contents to the destination instead of point the slice to the value. I'll work on that. Thanks for being a rubber duck.

from goon.

 avatar commented on July 20, 2024

Thanks for the explanation. I also learnt a few things!

from goon.

mzimmerman avatar mzimmerman commented on July 20, 2024

I had fixed this in my fork with revision 530e947
The key line is set.Elem().Set(reflect.ValueOf(dsts[0]).Elem()) which equates to *dst = *dsts[0]

from goon.

mzimmerman avatar mzimmerman commented on July 20, 2024

This was fixed in #13 and can be closed.

from goon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.