Commits

Sümer Cip committed 1015718

OOM tests somehow fails.

Comments (0)

Files changed (8)

-python ../test/test_fuzzy.py
+#python ../test/test_fuzzy.py
 python ../test/test_mem.py
-python ../test/test_protocol.py
-rm -f ../test/test_slab
-rm -f ../test/test_util
-gcc -std=c99 -pedantic -Wall -W -lm ../test/test_base.c ../test/test_slab.c ../src/slab.c -o ../test/test_slab -D LC_TEST -I ../src/ && ../test/test_slab
-gcc -std=c99 -pedantic -Wall -W -lm ../test/test_base.c ../test/test_util.c ../src/util.c -o ../test/test_util -D LC_TEST -I ../src/ && ../test/test_util
+#python ../test/test_protocol.py
+#rm -f ../test/test_slab
+#rm -f ../test/test_util
+#gcc -std=c99 -pedantic -Wall -W -lm ../test/test_base.c ../test/test_slab.c ../src/slab.c -o ../test/test_slab -D LC_TEST -I ../src/ && ../test/test_slab
+#gcc -std=c99 -pedantic -Wall -W -lm ../test/test_base.c ../test/test_util.c ../src/util.c -o ../test/test_util -D LC_TEST -I ../src/ && ../test/test_util
 echo "*** AUTOTESTS finished."
 sleep 10000
         }
         new->key = (char*)li_malloc(klen+1);
         if (!new->key) {
+            li_free(new);
             return HERROR;
         }
         memcpy(new->key, key, klen+1);
     
     conn->in = (request *)li_malloc(sizeof(request));
     if (!conn->in) {
+        // TODO: if we really fail here, we shall do something as 
+        // nobody can connect till we do something.
         return 0;
     }
   
     switch(state) {
     case READ_HEADER:
         if (!init_resources(conn)) {
+            LC_DEBUG(("req/resp resources cannot be initialized.\r\n"));
             disconnect_conn(conn); // we cannot receive anything.
             return;
         }
         if (ret == HERROR) {
             send_response(conn, OUT_OF_MEMORY);
             return;
-        }        
-        else if (ret == HEXISTS) { // key exists? then force-update the data
+        } else if (ret == HEXISTS) { // key exists? then force-update the data
             tab_item = hget(cache, conn->in->rkey, conn->in->req_header.request.key_length);
             assert(tab_item != NULL);
             del_cached_req(tab_item);
     // try to initialize the slab allocator. If slabs cannot uniformly distributed 
     // to all caches, then fallback to system's malloc 
     if (!init_cache_manager(settings.mem_avail/1024/1024, SLAB_SIZE_FACTOR)) {
-       goto err;
+        fprintf(stderr, "WARNING: falling back to system malloc.[%u,%u:%llu]\r\n", 
+                slab_stats.slab_count, slab_stats.cache_count, 
+                (unsigned long long)settings.mem_avail/1024/1024);
+        settings.use_sys_malloc = 1;           
+    } else {
+        if (slab_stats.slab_count < slab_stats.cache_count) {
+            fprintf(stderr, "WARNING: at least %u MB of memory " 
+                "is required to utilize the slab allocator,\r\n"
+                "falling back to system malloc.[%u,%u:%llu]\r\n", 
+                slab_stats.cache_count, slab_stats.slab_count, slab_stats.cache_count, 
+                (unsigned long long)settings.mem_avail/1024/1024);
+            settings.use_sys_malloc = 1;
+        } else {
+            LC_DEBUG(("using slab allocator with %llu MB of memory.\r\n", 
+                (unsigned long long int)settings.mem_avail/1024/1024));
+        }  
     }
-    if (slab_stats.slab_count < slab_stats.cache_count) {
-        fprintf(stderr, "WARNING: at least %u MB of memory " 
-            "is required to utilize the slab allocator,\r\n"
-            "falling back to system malloc.[%u,%u:%llu]\r\n", 
-            slab_stats.cache_count, slab_stats.slab_count, slab_stats.cache_count, 
-            (unsigned long long)settings.mem_avail/1024/1024);
-        settings.use_sys_malloc = 1;
-    } else {
-        LC_DEBUG(("using slab allocator with %llu MB of memory.\r\n", 
-            (unsigned long long int)settings.mem_avail/1024/1024));
-    }  
     
     // try to adjust system open file limit
     rlp.rlim_cur = rlp.rlim_max = settings.fd_limit; 
     }
     
 #ifdef MEM_DEBUG
-    LC_DEBUG(("Allocated memory.[%p]\r\n", p));
+    LC_DEBUG(("Allocated memory.[%p, %u]\r\n", p, (unsigned)size));
 #endif
 
     return p;
     if (!ptr) {
         return;
     }
-
-#ifdef MEM_DEBUG
-    LC_DEBUG(("Freeing memory.[%p]\r\n", ptr));
-#endif
     
     if (!settings.use_sys_malloc) {
         scfree(ptr);
         mem_used -= size;
         free(ptr);
     }
+
+#ifdef MEM_DEBUG
+    LC_DEBUG(("Freeing memory.[%p, %u]\r\n", ptr, (unsigned)size));
+#endif
 }
     request *in;					/* request */
     response out;					/* response */
     int free; 						/* recycle connection structure */
+    //int disconnect_after_send;      /* set this flag to disconnects the socket after send is completed */
     conn *next;						/* next connection in the linked-list of the connections */
 };
 

test/protocolconf.py

 INVALID_PARAM_SIZE = 0x03
 SUCCESS = 0x04
 INVALID_COMMAND = 0x05
+OUT_OF_MEMORY = 0x06
 
 def err2str(e):
 
         return "Success"
     elif e == INVALID_COMMAND:
         return "InvalidCommand"
+    elif e == OUT_OF_MEMORY:
+        return "OutOfMemory"
+    
     raise Exception, "Unrecognized error code received.[%d]" % (e)
         
     #    self.assertRaises( AssertionError, self.check_for_memusage_delta, ([("set", "a_unique_long_key_to_be_malloced", "value1", 1),])  )
     
     def test_out_of_memory(self):
+        self.client.flush_all()
         i = 0        
         while(True):
             self.client.set("key%d" % (i), "value(%d)" % (i), 100000)
             i += 1 
         # we are out of memory here, try to set some value
         self.client.set("oom_key", "oom_val", 1)
-        # TODO:        
+        self.assertErrorResponse(OUT_OF_MEMORY)       
+        
 
 if __name__ == '__main__':
     print "Running MemTests..."
 
 host = 'localhost'
 port = 13131 
-mem_avail = 4
+mem_avail = 1
 fd_limit = 2048
 
 #use_unix_socket = True
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.