From 0ff9e09c8f036ad99dcbe8a0768f3a29b149ce45 Mon Sep 17 00:00:00 2001
From: Roman Tsisyk <roman@tsisyk.com>
Date: Tue, 30 Sep 2014 14:27:04 +0400
Subject: [PATCH] Fix #536: fiber.info() doesn't list fibers with default names

---
 src/lua/fiber.cc        |  6 +++++-
 test/box/fiber.result   | 38 ++++++++++++++++++++++++++++++++++++++
 test/box/fiber.test.lua | 16 ++++++++++++++++
 3 files changed, 59 insertions(+), 1 deletion(-)

diff --git a/src/lua/fiber.cc b/src/lua/fiber.cc
index f8eda08a99..6d9e422018 100644
--- a/src/lua/fiber.cc
+++ b/src/lua/fiber.cc
@@ -220,9 +220,13 @@ lbox_fiber_statof(struct fiber *f, void *cb_ctx)
 {
 	struct lua_State *L = (struct lua_State *) cb_ctx;
 
-	lua_pushstring(L, fiber_name(f));
+	lua_pushinteger(L, f->fid);
 	lua_newtable(L);
 
+	lua_pushliteral(L, "name");
+	lua_pushstring(L, fiber_name(f));
+	lua_settable(L, -3);
+
 	lua_pushstring(L, "fid");
 	lua_pushnumber(L, f->fid);
 	lua_settable(L, -3);
diff --git a/test/box/fiber.result b/test/box/fiber.result
index 58656e42e8..13a1aa6044 100644
--- a/test/box/fiber.result
+++ b/test/box/fiber.result
@@ -726,6 +726,44 @@ done
 ---
 - true
 ...
+-- # gh-536: fiber.info() doesn't list fibers with default names
+--
+function loop() while true do fiber.sleep(10) end end
+---
+...
+f1 = fiber.create(loop)
+---
+...
+f2 = fiber.create(loop)
+---
+...
+f3 = fiber.create(loop)
+---
+...
+info = fiber.info()
+---
+...
+info[f1:id()] ~= nil
+---
+- true
+...
+info[f2:id()] ~= nil
+---
+- true
+...
+info[f3:id()] ~= nil
+---
+- true
+...
+f1:cancel()
+---
+...
+f2:cancel()
+---
+...
+f3:cancel()
+---
+...
 fiber = nil
 ---
 ...
diff --git a/test/box/fiber.test.lua b/test/box/fiber.test.lua
index 8c80a81c45..258561e06c 100644
--- a/test/box/fiber.test.lua
+++ b/test/box/fiber.test.lua
@@ -296,4 +296,20 @@ end;
 f = fiber.create(test)
 done
 
+-- # gh-536: fiber.info() doesn't list fibers with default names
+--
+function loop() while true do fiber.sleep(10) end end
+f1 = fiber.create(loop)
+f2 = fiber.create(loop)
+f3 = fiber.create(loop)
+
+info = fiber.info()
+info[f1:id()] ~= nil
+info[f2:id()] ~= nil
+info[f3:id()] ~= nil
+
+f1:cancel()
+f2:cancel()
+f3:cancel()
+
 fiber = nil
-- 
GitLab